Computing distances between things

  • Kevin

    Kevin - 2005-09-23

    I'm a new-comer to OpenCyc, and to start off, I'm trying to compute the distances between "features".   For example, lets say I have two orange construction cones in a one dimentional world, with specified coordinates: I want to know how far apart they are.

    I've been playing with this for two days now, and I haven't gotten it to work.  I'll post my "code" below, and I'd appreciate any insight as to why it's not working.


    Create    Feature
    Assert    (#$isa Feature Collection)
    Create    Cone1
    Create    Cone2
    Assert    (#$isa #$Cone1 #$Feature)
    Assert    (#$isa #$Cone2 #$Feature)

    Create    Location
    Assert    (#$isa Location AsymmetricBinaryPredicate)
    Assert    (#$arg1Isa Location Feature)
    Assert    (#$arg2Isa Location RealNumber)
    Assert    (#$Location #$Cone1 50)
    Assert    (#$Location #$Cone2 25)

    Create    DistanceBetweenFeatures
    Assert    (#$isa DistanceBetweenFeatures TernaryPredicate)
    Assert    (#$arg1Isa DistanceBetweenFeatures RealNumber)
    Assert    (#$arg2Isa DistanceBetweenFeatures Feature)
    Assert    (#$arg3Isa DistanceBetweenFeatures Feature)

    Assert    (#$implies (and
                (Location ?THING1 ?LOC1)
                (Location ?THING2 ?LOC2)
                (evaluate ?DIST (AbsoluteValueFn (DifferenceFn ?LOC1 ?LOC2))))
            (DistanceBetweenFeatures ?DIST ?THING1 ?THING2))

    All the above gets entered into the KB nicely, but when I try to test the DistanceBetweenFeatures predicate, it exhausts all paths before it comes up with an answer.  I've tried the following:

    Ask    (#$DistanceBetweenFeatures ?DIST #$Cone1 #$Cone2)
    Ask    (#$DistanceBetweenFeatures 25 #$Cone1 #$Cone2)

    • nanoguy

      nanoguy - 2006-05-12

      The problem was that the Cones didn't have a slot for storing location.
      If you queried thier location, they didn't have any.

      Ask (Location Cone1 ?LOC1)
      Didn't return anything

      The problem was the Cones were not correctly defined.  It turns out that cyc has a exiting collection: Cone

      So I also defined them:
      Assert (isa Cone1 Cone)
      Assert (isa Cone2 Cone)

      Once I defined them as Cone then I got this query to work:
      Ask (and
            (Location Cone1 ?LOC1)
            (Location Cone2 ?LOC2)
            (evaluate ?DIST
                  (DifferenceFn ?LOC1 ?LOC2))))

      I am also new to cyc too, but I think your predicate function is not fully defined. 

      I have been trying to figure out how to add values to the instances and haven't quite figured it out yet. 

      Good luck.

      Please post your code once you get it fully working.  There is not enough examples of cyc code to use as examples.  You should probably also create a microTheory to put your stuff in when functional.

      - Tom aka nanoguy


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks