开发者

Framework for user defined relationships

I'm thinking about creating a Django-powered website where users would be able to relate entities to each other. Examples would for instance include: "John is married to Mary" or "John works at Google".

Users should be able to define the entities and their relationships themselves (and will typically define relations of other people, not of themselves). Ideally, users enter these relations as free text (where subject and object could perhaps be an a开发者_运维知识库utocomplete field, based on previously entered existing entities).

Django's model framework is ideal for storing the entities and their relations, but how would one make such a thing manageable on a higher level?

Is there a Python-powered ontological framework (thanks duffymo) that would help me derive structure out of these user-generated relationships? I'm looking for ways to for example derive reversible relations, aggregate relations (e.g. "3 persons are family relations of John"), classify into types of relations (family relations, work relations, ...), and this all based on user generated input and not a (known) predefined set of relations. It

Thanks in advance,

Mathieu


There's Protege, the Stanford ontology program. If you can run it for Java, perhaps you can run it for Jython.

http://protege.stanford.edu/conference/2004/slides/3.3_dameron_7-7-04.pdf


Disclaimer: I am not an expect. I'm learning Django in my spare time. That said..

You may want to look at the "many to many through" as a field relationship.

From the docs:

http://docs.djangoproject.com/en/dev/topics/db/models/

When you're only dealing with simple many-to-many relationships such as mixing and matching pizzas and toppings, a standard ManyToManyField is all you need. However, sometimes you may need to associate data with the relationship between two models.

Where the syntax look like this (also from the example in the docs):

class Group(models.Model):
    name = models.CharField(max_length=128)
    members = models.ManyToManyField(Person, through='Membership')

    def __unicode__(self):
        return self.name


Users are able to define the relationships themselves (and will typically define relations of other people, not of themselves);

Fine.

there is in other words no pre-defined set of possible relations.

So? This isn't an interesting constraint. Why mention it?

Ideally, users enter these relations as free text (where subject and object could perhaps be an autocomplete field).

Fine.

 class Person( models.Model ):
     # whatever

 class RelatedTo( models.Model ):
     one_person= models.ForeignKey( Person, related_name="me" )
     other_person= models.ForeignKey( Person, related_name="them" )
     relationship = models.TextField( )

That's one way to do it. It's not difficult if you make the "relationship" a first-class object.

If you want multi-party relationships, it works like this.

 class Person( models.Model ):
     # whatever

 class RelatedTo( models.Model ):
     relationship_type = models.TextField( )

 class Party( models.Model ):
     relationship = ForeignKeyField( RelatedTo )
     role = models.TextField()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜