Showing posts with label opencyc. Show all posts
Showing posts with label opencyc. Show all posts

Saturday, 16 February 2013

OpenCyc experimentation

Last December, OpenCyc 4.0 was released. I've been meaning to get more familiar with OpenCyc for a long time, and luckily this release adds a lot of interface improvements.

  • The search bar now has a drop down set of auto-complete matches.
  • The display for a selected term is cleaner and easier to use.
  • Terms have a popup menu that allows easy editing or deletion.
Experiment

I was hoping to translate the D&D SRD ability modifier formula into a CycL function, so that I could at a later point calculate the modifier for the given attribute of an entity. The OpenCyc documentation was never extensive enough to describe how to do this sort of thing, and it has not been updated since the original 1.0 release. Add into that dead links, and working out how to use OpenCyc is pretty hard going.

A huge amount of browsing terms in the OpenCyc ontology browser led me to the simple formula:
(#$TruncateFn (#$QuotientFn (#$DifferenceFn ?SCORE 10) 2))
And that's ignoring that I had trouble finding DifferenceFn and QuotientFn, originally using PlusFn and TimesFn in their places.

In order to test an expression like this, it needs to be wrapped in evaluate, which binds the result to a variable allowing it to be seen in the query page.
(#$evaluate ?RESULT (#$TruncateFn (#$QuotientFn (#$DifferenceFn ?SCORE 10) 2)))
Like a SELECT statement in SQL, this effectively displays one row with one column named RESULT showing the value of 3.

Defining the standard terms for a CycL function is pretty simple.

The first step is to create a term (a generic step) with the name of the function, in this case #$AbilityScoreModifierFn. In the top frame, there is a tools link on the right hand side. Click on this, and then select Create Term.

Next various properties are asserted for the term. In the top frame, there is a Assert link. Click on this, and then simply enter the relevant expressions and assert each in turn.
(#$isa #$AbilityScoreModifierFn #$UnaryFunction)
(#$arity #$AbilityScoreModifierFn 1)
(#$arg1Isa #$AbilityScoreModifierFn #$Integer)
(#$resultIsa #$AbilityScoreModifierFn #$Integer)
And finally the remaining task, is to associate the formula with the AbilityScoreModifierFn function. I've come to the conclusion that this actually isn't possible to do from within CycL.

There are two possible ways of associating logic with a term (that I've been able to find).
  1. rewriteOf
  2. evaluationDefn
With rewriteOf, you might assert something like:
(#$rewriteOf #$AbilityScoreModifierFn
  (#$Lambda (?SCORE) (#$TruncateFn (#$QuotientFn (#$DifferenceFn ?SCORE 10) 2))))
Unfortunately, rewriteOf expects a reifiable function as it's second argument. What this means, is that what this does is assert (#$AbilityScoreModifierFn 18) as a fact in the ontology. This is obviously not what I want, which is simply calculate and output a value, with no side-effects.

CycL expressions cannot be associated with evaluationDefn. This is intended rather to simply specify the name of a function in the lower level lisp language, called SubL. These are apparently easy enough to define, but it has been hard enough getting to this point, let along adding further complication outside of the ontology.

Experiment conclusion

At this point, I get the feeling it isn't intended that you can directly create formulas as expressions within CycL. Instead, I assume that it is expected that these are defined in SubL.

Ontology thoughts

I'm also not entirely sure that the effort of using OpenCyc is worth it. While there is a wealth of knowledge in the ontology, it doesn't seem deep enough in the right places to be used to back a game experience.

There are definitions for Crossbow and Longbow for instance, but they don't have the depth which there is for Gun. Gun has logic to define information about its projectiles, and defines the parts that make up both guns and their projectiles. But there is no corresponding breakdown of the parts of a bow, or the projectile which a bow fires.

The humanoid body has parts, but there is no definition of how the parts join together. Actually, that's not entirely true. I believe there are a few definitions of which rib comes before the next, but little more. Torso doesn't seem to be joined to arms, neck and legs or whatever it should be joined to. Of course, cutting up corpses is not a crucial MUD feature, but I believe this is illustrative of a general lack of depth where it counts.

OpenCyc thoughts

Do you know how much memory OpenCyc requires to run out of the box? A minimum of 5 gigabytes. Who wants to run a MUD and to have to run a second process which they connect to via SOAP, which uses this much memory? And who wants to write their own SOAP encoding of their queries and other commands directed at the OpenCyc process, because there are only Java bindings provided?

At this point I am wondering if there is any reason to bother experimenting further.

Friday, 9 December 2011

OpenCycloGraph

A recent post to MudBytes on using real world natural resource and mineral data to make a game, made me think of OpenCyc.  I've played around with it in the past, but it is somewhat complicated.  Starting it up also starts up a web interface through which the ontology can be either clicked through, or searched for specific terms.  Even so, it is still hard to get a grip on what is in there and what it means.


Even people who know it well enough to be ready to extend the ontologies are warned that it can be difficult to know whether whatever you wish to add is in there or not.  Just clicking through the data, or searching on relevant searching terms that come to mind, I sort of wished for a graph to click through.  And this reminded me of opencyclograph.  OpenCycloGraph can be pointed at a running instance of OpenCyc, and from there it can fetch and display the hierarchy of concepts.


In the screenshot above, it can be seen showing the results of a search for "Mineral".

Unfortunately, OpenCycloGraph is not quite ready for use.  There are no binaries provided at the Google Code project.  This means that anyone wanting to use it, needs to do a little bit of legwork.  I'll note below what I did, although I've never really worked in Java or used this IDE before, so maybe I'm doing it a little harder than I need to.

  1. Download and install NetBeans.
  2. Run NetBeans and import the code as a project.
  3. Find the "GLPanel.java" file under CycloGraph/src/com.touchgraph.graphlayout in NetBeans.
  4. Right click on it, and select "Run File".
At this point, you will see a window looking something like the above.  However, it won't be able to find a running instance of OpenCyc so it won't really be useful.
  1. Download and extract OpenCyc 2.0.
  2. Try and run its "scripts/run-cyc.bat".  If it fails due to lack of memory, edit the BAT script and modify it to run the 64-bit version (this is a two line change).
  3. Once it has started running on "localhost" up go back into NetBeans.
  4. Search for "CycServer" which is used in OpenCycloGraph as the default address where it should look for a running instance of OpenCyc.  It should be in "GLPanel.java", line 1282.  Replace it with "localhost".


Now when you right-click on "GLPanel.java" and select "Run File", it should "work correctly" for selected values of "work correctly".

You start by entering a search term and hitting enter.


This will populate the graph, and from there you can click on related entries of interest.



Note that you can see what the relation is, for example above you can see that "NonMetal" is 'disjointWith' "Metal" which seems not very useful to the end user and more likely was added to help out OpenCyc inferencing.

If you find a node and want to know more, you can right click and select "Inspect Node" to update/synchronise the browser display in the left-hand pane. 


And that's about it.  There's a video of me generically browsing game world relevant information for about a minute and a half below.  One application would be adding a "light" verb and linking it to objects which are CombustibleFuelSources, for instance.


An aspect of OpenCyc that escapes me is that either some data is missing and was not released as part of the cut-down OpenCyc public ontology, or I just don't know how to query it yet.  Case in point is Mass, massOfObject and MassOfObjectFn.  I am unable to locate any entries which map values for these to other ontology objects.