web analytics

Stalled and Distracted

Not much visible progress in the last several weeks. I’ve been off wandering in the world of Python software development with forays into the Twitter API,  using sockets for inter-process communication, and a dozen other fascinating areas. Lots of new code written. Almost all the old code seems broken in some way or other.

So, it’s time to take stock of where we are on this journey. To that end, I’m going to  try and document the bits that I have, and the challenges as I see them now. The bits will be in the order I think of them, so probably won’t make sense.

1. SemNet

This bit started life as code I found here that “defined several simple classes for building and using semantic networks.” It defined three classes: Entity, Relation, and Fact. It allows statements like these:

>>> animal = Entity("animal")
>>> fish = Entity("fish")
>>> trout = Entity("trout")

>>> isa = Relation("is-a",True)

>>> Fact(fish, isa, animal)
>>> Fact(trout, isa, fish)

Having defined these variables, statements like this were easy:

>>> print "trout is a fish?", isa(trout,fish)
trout is a fish? True
>>> print "trout is an animal?", isa(trout,animal)
trout is an animal? True

The trouble came when I tried to persist the relations to a file. It turns out that the “Entity” object is storing the “isa” object in its list of known facts (actor-relation-object). Of course when the entity object is reloaded from disk, the relation object is a different object than the signature that was stored, so things come unraveled.

That has lead me into trying to figure out how to persist and recreate objects without losing the network relationships. I suspect there is an easy pattern for this sort of thing, but I’m not a skilled enough programmer to see it immediately.

More adventures will follow…

Author: Rob

I'm a retired engineer, a Jesus-follower, a long-time computer hobbyist, a Starfinder GM, a sometimes player of chess, and a solidly mediocre guitar strummer.

One thought on “Stalled and Distracted”

  1. The pattern you’re thinking of is “serialization”, as implemented in many class libraries. These libraries handle object references by building a dictionary of objectIDs and object references (or pointers). When you serializing to disk, as you process each object you look it up in the dictionary. If it’s not there you assign it a unique ID and add it to the dictionary. Then you right the object’s ID with it to disk. Whenever you need to serialize an object reference (pointer) you write its ID to disk instead.

    When you deserialize you reverse the process. Each time you read an object into memory you add it to the dictionary. Each time you read an object ID you replace it with the corresponding object reference (pointer).

    This works because you the order you serialize an object is by following a depth first traverse of its web of references. If you encounter an object you haven’t seen before (its not in the dictionary) you recurse and serialize it before going on to the next member in the current object.

    Perhaps you were asking a different question. Did I just explain something you already knew?

Comments are closed.