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.

Monday, 4 February 2013

pysrd

One of my long-term projects is to programmatically generate game logic from the D&D 3.5 SRD.  The idea is that ideally if the required legwork was done, any time I wanted to prototype something around a game experience, it should be possible to plug in the processed data and be 98% of the way to having stock D&D gameplay.  There's a lot of hand-waving there around the phrase "required legwork", but that's not really important for the purpose of this post.


I've extracted the low level scripts I use to both extend the database and introspect it's contents, and published them on github under the project name pysrd.




The SRD is available from Wizards of the Coast as a set of RTF documents.  This of course, is not ideal, but fortunately it is possible to get the data from andargor.com in different database formats, including SQLite.  Unfortunately however, not all SRD data is included in these databases.  Fortunately, the OpenSRD project includes generated HTML versions of the RTF documents, which can more easily be processed.

Wednesday, 23 January 2013

The one thing I wish I knew about unlocking my Android phone

For some reason I decided to unlock my HTC One X phone. I believe it was because your phone comes bundled with a fixed set of applications that you can't remove. These take up about three screens, and result in paging through trying to find the useful ones you actually installed. You do this by going through several steps, one of which is visiting www.htcdev.com and getting a code.

But what you probably don't realise, as I didn't, is that this clears your device's cid code. Your cid code is what defines the operator who provide you with updates. When you apply an update, the update has a cid check embedded in it, and will error helpfully leaving a red triangle surrounding an exclamation mark on a black screen.

Once you have cleared your cid code, there is not way of setting it again. Not for an HTC One X device at least. The reason for this is that there is apparently something called S-ON and S-OFF, and if your device is S-ON then you cannot alter things like the cid code. HTC choose not to allow toggling this off for the One X. If you can toggle it off, it is apparently easy to set it again with a fastboot command.

TL;DR: Don't unlock your HTC Android device unless you know you can set it to S-OFF. Otherwise, you won't be able to apply the updates you download from whatever telecom company provides them.