This project has moved and is read-only. For the latest updates, please go here.

Programmatically write the properties of the triple

Jul 21, 2014 at 11:20 AM
Hi there,

Is there a way to programmatically write the properties of the triple into the database?

I have a Production class that has a ProductionMembers collection, each ProductionMember is made of a Person and a Role.

I would like ProductionMember to be written as one triple:

ProductionMember Role Person

or better

Production Role Person (though I know that here we skipped the ProductionMember obj of the domain, so I guess that would not be possible?)

There are no set roles, and new roles can be added, so I am bound to have them as a property of the ProductionMember. However for someone who consumes the data, this structure may look too complicated..

Thanks!
Jul 29, 2014 at 2:26 PM
NZ_Dig wrote:
Hi there,

Is there a way to programmatically write the properties of the triple into the database?

I have a Production class that has a ProductionMembers collection, each ProductionMember is made of a Person and a Role.

I would like ProductionMember to be written as one triple:

ProductionMember Role Person

or better

Production Role Person (though I know that here we skipped the ProductionMember obj of the domain, so I guess that would not be possible?)

There are no set roles, and new roles can be added, so I am bound to have them as a property of the ProductionMember. However for someone who consumes the data, this structure may look too complicated..

Thanks!
In general if you want to add properties to a relationship then the relationship itself needs to be a resource. For example if I want to say that Henry VIII was King of England I could just do:

Henry_VIII king_of England

but if I want to say that Henry VIII was King of England from 1509 to 1547, then I need to create a resource for the notion of "Henry VIII being king". Lets call it a "kingship" :)

henry_vii_kingship type kingship
henry_vii_kingship ruler Henry_VIII
henry_vii_kingship ruled England
henry_vii_kingship startDate 1509
henry_vii_kingship endDate 1527
henry_vii_kingship endedBy death

as you can see, now that I have "kingship" as a resource I can say all sorts of things about it. Although this is a little more complex to consume it has one advantage that everything you need to know about that kingship is right there.

So I think it sounds like you are going in the right direction. I think if you turn around your view and look at it from the point of view of the "role in a production" you will get the structure you need and it won't be too hard to consume / explain to data consumers.
Jul 30, 2014 at 11:50 AM
Hi Kal,

Thank you.

Would you be able to clarify of how the 'direction of triples' is being determined when you have many-to-many relationships.

I have changed my model (so it is different to the one above):
 [Entity("http://xmlns.com/foaf/0.1/Person")]
    public interface IPerson
    {
        ...

        ICollection<IProduction> Productions { get; set; }

        [PropertyType("arts:performed")]
        [InverseProperty("PerformedBy")]
        ICollection<IRole> Roles { get; set; }
    }
So with the Productions collections, the inverse property is defined in the IProduction interface:
    [Entity]
    public interface IProduction
    {
        [PropertyType("arts:performer")]
        [InverseProperty("Productions")]
        ICollection<IPerson> Performers { get; set; }
   
    }
But with the Roles collection the inverse property is determined within the IPerson interface.

Even though the 'direction' of definition is opposite, both saved in the database as same 'direction' triples:

Juliet_Binoche productions Mademoiselle_Julie_2012
Juliet_Binoche performed Mademoiselle_Julie

I would like the first triple t be the other way around

Mademoiselle_Julie_2012 performer Juliet_Binoche.

How can I control the 'direction' of triples in this instance?

Thanks!
Jul 30, 2014 at 12:19 PM
Hi,

You don't need to mix [PropertyType] and [InverseProperty] - in fact you probably shouldn't do this! Instead use [PropertyType] on the property that you want to be the "forward" direction for the triple, and use [InverseProperty] on the property that you want to be the reverse direction. I think this should do what you want:
[Entity]
public interface IRole {
  [PropertyType("arts:performer")]
  ICollection<IPerson> Performers { get; set; }
}

[Entity]
public IProduction {
  [InverseProperty("Productions")]
  ICollection<IPerson> Cast { get; set; }
}

[Entity]
public interface IPerson {
  [InverseProperty("Performers")]
  ICollection<IRole> Roles {get;set;}

  [PropertyType("arts:productions")]
  ICollection<IProduction> Productions {get;set;}
}
That should result in:

Juliette_Binoche arts:productions Mademoiselle_Julie_2012
Mademoiselle_Julie arts:performer Juliette_Binoche

Note that there is also a slightly different pattern you can use when you want the triple to be one way round and the C# class property to be expressed the other way around and don't want to also have the forward version as a C# property, using the [InversePropertyType] decorator.

Cheers

Kal
Jul 30, 2014 at 12:57 PM
Perfect! Thank you!