Semantics.SDK: RdfObjects FAQ
Questions related to ontology objects:
- How do I generate .NET objects from an ontology?
- How do I get an XSD schema from an ontology object?
- How do I output an ontology object as XML?
- How do I create an ontology object from XML?
- How do I create an explicit relationship between two ontology objects?
- How do I create an inferred relationship between two ontology objects?
How do I generate .NET objects from an ontology?
Please click the following link to open the Object Generation User Guide in a new window.
Back to Top
How do I get an XSD schema from an ontology object?
Every RdfObject has an overloaded GetSchema() for obtaining the object's XSD schema. The example below demonstrates outputting the schema to the console.
- public void Get_an_XSD_Schema_from_an_Ontology_Object()
- {
- Person.GetSchema().Write(Console.Out);
- }
Output:
Due to the length of the output generated by the following code, it will not be displayed.
Back to Top
How do I output an ontology object as XML?
Every RdfObject has an overloaded ToXml() method that provides multiple ways to obtain an XML representation of the ontology object.
- public void Output_an_Ontology_Object_as_XML()
- {
- FoafContext ctx = new FoafContext();
- Person justin = ctx.Create<Person>(new RdfUri("http://www.intellidimension.com/people#JBarron"));
-
-
-
-
-
-
-
- justin.Birthday = "01-01";
-
-
-
- justin.FirstName = "Justin";
- justin.Family_name = "Barron";
- justin.Gender = "male";
- justin.MsnChatID.Add("jbarron@intellidimension.com");
- justin.MsnChatID.Add(new RdfLiteral("jbarron@intellidimension.com"));
-
- Console.WriteLine(justin.ToXml());
- }
Output:
<?xml version="1.0" encoding="utf-16"?>
<RdfObjects>
<RdfObject>
<Person id="http://www.intellidimension.com/people#JBarron">
<MsnChatID isUri="false" datatype="" lang="" value="jbarron@intellidimension.com" />
<Gender isUri="false" datatype="" lang="" value="male" />
<FirstName isUri="false" datatype="" lang="" value="Justin" />
<Family_name isUri="false" datatype="" lang="" value="Barron" />
<Birthday isUri="false" datatype="" lang="" value="01-01" />
</Person>
</RdfObject>
</RdfObjects>
Back to Top
How do I create an ontology object from XML?
Every RdfObject has an overloaded FromXml() method that provides multiple ways to create an ontology object from XML.
- public void Create_an_Ontology_Object_from_XML()
- {
- String input = @"<?xml version=""1.0"" encoding=""utf-16""?>
- <RdfObjects>
- <RdfObject>
-
<Person id=""http://www.intellidimension.com/people#JBarron"">
-
<MsnChatID isUri=""false"" datatype="""" lang="""" value=""jbarron@intellidimension.com"" />
-
<Gender isUri=""false"" datatype="""" lang="""" value=""male"" />
-
<FirstName isUri=""false"" datatype="""" lang="""" value=""Justin"" />
-
<Family_name isUri=""false"" datatype="""" lang="""" value=""Barron"" />
-
<Birthday isUri=""false"" datatype="""" lang="""" value=""01-01"" />
- </Person>
- </RdfObject>
- </RdfObjects>";
- XmlReader reader = XmlReader.Create(new StringReader(input));
- FoafContext ctx = new FoafContext();
- Person justin = ctx.FromXml<Person>(reader);
-
- Console.WriteLine(justin.ToXml());
- }
Output:
<?xml version="1.0" encoding="utf-16"?>
<RdfObjects>
<RdfObject>
<Person id="http://www.intellidimension.com/people#JBarron">
<MsnChatID isUri="false" datatype="" lang="" value="jbarron@intellidimension.com" />
<Gender isUri="false" datatype="" lang="" value="male" />
<FirstName isUri="false" datatype="" lang="" value="Justin" />
<Family_name isUri="false" datatype="" lang="" value="Barron" />
<Birthday isUri="false" datatype="" lang="" value="01-01" />
</Person>
</RdfObject>
</RdfObjects>
Back to Top
How do I create an explicit relationship between two ontology objects?
Relationships can be defined between ontology objects depending on the ontology being used. The example below demonstrates the explicit declaration of a foaf:knows relationship between two Person objects generated using the FOAF ontology.
- public void Create_an_Explicit_Relationship_Between_Two_Ontology_Objects()
- {
- FoafContext ctx = new FoafContext();
-
- Person justin = ctx.Create<Person>(new RdfUri("http://www.intellidimension.com/people#JBarron"));
- justin.FirstName = "Justin";
- justin.Family_name = "Barron";
- justin.Mbox.Add(new RdfLiteral("jbarron@intellidimension.com"));
-
- Person derrish = ctx.Create<Person>(new RdfUri("http://www.intellidimension.com/people#DRepchick"));
- derrish.FirstName = "Derrish";
- derrish.Family_name = "Repchick";
- derrish.Mbox.Add(new RdfLiteral("drepchick@intellidimension.com"));
-
-
- justin.Knows.Add(derrish);
- derrish.Knows.Add(justin);
-
-
- Console.WriteLine("Justin knows Derrish: {0}", justin.Knows.Contains(derrish));
- Console.WriteLine("Derrish knows Justin: {0}", derrish.Knows.Contains(justin));
- }
Output:
Justin knows Derrish: True
Derrish knows Justin: True
Back to Top
How do I create an inferred relationship between two ontology objects?
Relationships can be defined between ontology objects depending on the ontology being used. The example below demonstrates the inferred declaration of a foaf:knows relationship between two Person objects generated using the FOAF ontology by introducing an inference rule to the graph.
- public void Create_an_Inferred_Relationship_Between_Two_Ontology_Objects()
- {
-
- string ruleSparql = @"prefix foaf: <http://xmlns.com/foaf/0.1/>
- with (
-
construct {?o foaf:knows ?s}
-
where {?s foaf:knows ?o}
- )
-
construct {?s ?p ?o}
- where {?s ?p ?o}";
-
-
- AbstractQuery rule = new SparqlParser().Parse(ruleSparql, new ClientModel());
-
-
- FoafContext ctx = new FoafContext(new GraphDataSource(), rule);
-
- Person justin = ctx.Create<Person>(new RdfUri("http://www.intellidimension.com/people#JBarron"));
- justin.FirstName = "Justin";
-
- Person derrish = ctx.Create<Person>(new RdfUri("http://www.intellidimension.com/people#DRepchick"));
- derrish.FirstName = "Derrish";
-
- justin.Knows.Add(derrish);
-
-
- Console.WriteLine("Justin knows Derrish: {0}", justin.Knows.Contains(derrish));
- Console.WriteLine("Derrish knows Justin: {0}", derrish.Knows.Contains(justin));
- Console.WriteLine();
-
-
-
-
- new InferenceDataSource(((InferenceDataSource)ctx.Datasource).Facts, rule).Format<RdfXmlFormatter>(Console.Out);
- }
Output:
Justin knows Derrish: True
Derrish knows Justin: True
<?xml version="1.0" encoding="utf-16"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:ns1="http://xmlns.com/foaf/0.1/">
<rdf:Description rdf:about="http://www.intellidimension.com/people#DRepchick">
<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person" />
<ns1:firstName>Derrish</ns1:firstName>
<ns1:knows rdf:resource="http://www.intellidimension.com/people#JBarron" />
</rdf:Description>
<rdf:Description rdf:about="http://www.intellidimension.com/people#JBarron">
<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person" />
<ns1:firstName>Justin</ns1:firstName>
<ns1:knows rdf:resource="http://www.intellidimension.com/people#DRepchick" />
</rdf:Description>
</rdf:RDF>
Back to Top
|