public void cloneReturnsTripleStoreContainingSameStatements() { TripleStore store = MakeNewTripleStore(); store.Add(new Statement(new BlankNode(), new UriRef("http://example.com/pred"), new BlankNode())); store.Add(new Statement(new BlankNode(), new UriRef("http://example.com/pred2"), new PlainLiteral("foo", "jp"))); store.Add(new Statement(new UriRef("http://example.com/the-thing"), new UriRef("http://example.com/pred3"), new TypedLiteral("1", "http://example.com/types/numeric"))); store.Add(new Statement(new UriRef("http://example.com/other-thing"), new UriRef("http://example.com/pred4"), new UriRef("http://example.com/the-thing"))); TripleStore clone = (TripleStore)store.Clone(); Assert.AreEqual(store.NodeCount, clone.NodeCount); Assert.AreEqual(store.ResourceCount, clone.ResourceCount); TripleStoreVerifier verifier = new TripleStoreVerifier(); verifier.expect("_:a <http://example.com/pred> _:b ."); verifier.expect("_:c <http://example.com/pred2> \"foo\"@jp ."); verifier.expect("<http://example.com/the-thing> <http://example.com/pred3> \"1\"^^<http://example.com/types/numeric> ."); verifier.expect("<http://example.com/other-thing> <http://example.com/pred4> <http://example.com/the-thing> ."); Assert.IsTrue(verifier.verify(clone)); clone.Clear(); store.Clear(); }
public void cloneReturnsObjectOfSameType() { TripleStore store = MakeNewTripleStore(); TripleStore clone = (TripleStore)store.Clone(); Assert.AreEqual(store.GetType(), clone.GetType()); clone.Clear(); store.Clear(); }
public void CloneReturnsIndependentTripleStore() { TripleStore store = MakeNewTripleStore(); store.Add(new Statement(new BlankNode(), new UriRef("http://example.com/pred"), new BlankNode())); TripleStore clone = (TripleStore)store.Clone(); int cloneNodeCountBefore = clone.NodeCount; int cloneResourceCountBefore = clone.ResourceCount; store.Add(new Statement(new BlankNode(), new UriRef("http://example.com/pred"), new BlankNode())); Assert.AreEqual(cloneNodeCountBefore, clone.NodeCount, "Clone node count is unchanged"); Assert.AreEqual(cloneResourceCountBefore, clone.ResourceCount, "Clone resource count is unchanged"); store.Clear(); Assert.AreEqual(cloneNodeCountBefore, clone.NodeCount, "Clone node count is unchanged after Clearing original"); Assert.AreEqual(cloneResourceCountBefore, clone.ResourceCount, "Clone resource count is unchanged after Clearing original"); }
/// <summary>Applies inference rules to assertions in the KnowledgeBase.</summary> public virtual void Think() { // Implementation of this method has not been optimised for efficiency. Focus is on correctness for now itsInferences = (TripleStore)itsAssertions.Clone(); itsInferences.Add(itsSchemas); Rule axioms = MakeAxioms(); itsInferences.Evaluate(axioms); int previousStatementCount = 0; ArrayList rules = new ArrayList(); Rule rdf1 = new Rule(); rdf1.AddAntecedent(new Pattern(new Variable("uuu"), new Variable("aaa"), new Variable("yyy"))); rdf1.AddConsequent(new Pattern(new Variable("aaa"), Schema.rdf.type, Schema.rdf.Property)); rules.Add(rdf1); Rule rdfs2 = new Rule(); rdfs2.AddAntecedent(new Pattern(new Variable("aaa"), Schema.rdfs.domain, new Variable("xxx"))); rdfs2.AddAntecedent(new Pattern(new Variable("uuu"), new Variable("aaa"), new Variable("yyy"))); rdfs2.AddConsequent(new Pattern(new Variable("uuu"), Schema.rdf.type, new Variable("xxx"))); rules.Add(rdfs2); Rule rdfs3 = new Rule(); rdfs3.AddAntecedent(new Pattern(new Variable("aaa"), Schema.rdfs.range, new Variable("xxx"))); rdfs3.AddAntecedent(new Pattern(new Variable("uuu"), new Variable("aaa"), new Variable("vvv"))); rdfs3.AddConsequent(new Pattern(new Variable("vvv"), Schema.rdf.type, new Variable("xxx"))); rules.Add(rdfs3); Rule rdfs4 = new Rule(); rdfs4.AddAntecedent(new Pattern(new Variable("uuu"), new Variable("aaa"), new Variable("xxx"))); rdfs4.AddConsequent(new Pattern(new Variable("uuu"), Schema.rdf.type, Schema.rdfs.Resource)); rdfs4.AddConsequent(new Pattern(new Variable("xxx"), Schema.rdf.type, Schema.rdfs.Resource)); rules.Add(rdfs4); Rule rdfs5 = new Rule(); rdfs5.AddAntecedent(new Pattern(new Variable("uuu"), Schema.rdf.type, Schema.rdf.Property)); rdfs5.AddConsequent(new Pattern(new Variable("uuu"), Schema.rdfs.subPropertyOf, new Variable("uuu"))); rules.Add(rdfs5); Rule rdfs6 = new Rule(); rdfs6.AddAntecedent(new Pattern(new Variable("uuu"), Schema.rdfs.subPropertyOf, new Variable("vvv"))); rdfs6.AddAntecedent(new Pattern(new Variable("vvv"), Schema.rdfs.subPropertyOf, new Variable("xxx"))); rdfs6.AddConsequent(new Pattern(new Variable("uuu"), Schema.rdfs.subPropertyOf, new Variable("xxx"))); rules.Add(rdfs6); Rule rdfs7 = new Rule(); rdfs7.AddAntecedent(new Pattern(new Variable("aaa"), Schema.rdfs.subPropertyOf, new Variable("bbb"))); rdfs7.AddAntecedent(new Pattern(new Variable("uuu"), new Variable("aaa"), new Variable("yyy"))); rdfs7.AddConsequent(new Pattern(new Variable("uuu"), new Variable("bbb"), new Variable("yyy"))); rules.Add(rdfs7); Rule rdfs8and10 = new Rule(); rdfs8and10.AddAntecedent(new Pattern(new Variable("uuu"), Schema.rdf.type, Schema.rdfs.Class)); rdfs8and10.AddConsequent(new Pattern(new Variable("uuu"), Schema.rdfs.subClassOf, Schema.rdfs.Resource)); rdfs8and10.AddConsequent(new Pattern(new Variable("uuu"), Schema.rdfs.subClassOf, new Variable("uuu"))); rules.Add(rdfs8and10); Rule rdfs9 = new Rule(); rdfs9.AddAntecedent(new Pattern(new Variable("uuu"), Schema.rdfs.subClassOf, new Variable("xxx"))); rdfs9.AddAntecedent(new Pattern(new Variable("vvv"), Schema.rdf.type, new Variable("uuu"))); rdfs9.AddConsequent(new Pattern(new Variable("vvv"), Schema.rdf.type, new Variable("xxx"))); rules.Add(rdfs9); Rule rdfs11 = new Rule(); rdfs11.AddAntecedent(new Pattern(new Variable("uuu"), Schema.rdfs.subClassOf, new Variable("vvv"))); rdfs11.AddAntecedent(new Pattern(new Variable("vvv"), Schema.rdfs.subClassOf, new Variable("xxx"))); rdfs11.AddConsequent(new Pattern(new Variable("uuu"), Schema.rdfs.subClassOf, new Variable("xxx"))); rules.Add(rdfs11); Rule rdfs12 = new Rule(); rdfs12.AddAntecedent(new Pattern(new Variable("uuu"), Schema.rdf.type, Schema.rdfs.ContainerMembershipProperty)); rdfs12.AddConsequent(new Pattern(new Variable("uuu"), Schema.rdfs.subPropertyOf, Schema.rdfs.member)); rules.Add(rdfs12); Rule rdfs13 = new Rule(); rdfs13.AddAntecedent(new Pattern(new Variable("uuu"), Schema.rdf.type, Schema.rdfs.Datatype)); rdfs13.AddConsequent(new Pattern(new Variable("uuu"), Schema.rdfs.subClassOf, Schema.rdfs.Literal)); rules.Add(rdfs13); /* * Can also add following OWL entailment rules * (after Herman J. ter Horst, Extending the RDFS Entailment Lemma, Proceedings of 3rd International Semantic Web Conference) * * rdfp1: (?p rdf:type owl:FunctionalProperty) (?u ?p ?v) (?u ?p ?w) where v is URI or BlankNode then add (?v owl:sameAs ?w) * rdfp2: (?p rdf:type owl:InverseFunctionalProperty) (?u ?p ?w) (?v ?p ?w) then add (?u owl:sameAs ?v) * rdfp3: (?p rdf:type owl:SymmetricProperty) (?v ?p ?w) where w is URI or BlankNode then add (?w ?p ?v) * rdfp4: (?p rdf:type owl:TransitiveProperty) (?u ?p ?v) (?v ?p ?w) then add (?u ?p ?w) * rdfp5a: (?v ?p ?w) then add (?v owl:sameAs ?v) * rdfp5b: (?v ?p ?w) where w is URI or BlankNode then add (?w owl:sameAs ?w) * rdfp6: (?v owl:sameAs ?w) where w is URI or BlankNode then add (?w owl:sameAs ?v) * rdfp7: (?u owl:sameAs ?v) (?v owl:sameAs ?w) then add (?u owl:sameAs ?w) * rdfp8a: (?p owl:inverseOf ?q) (?v ?p ?w) where w is URI or BlankNode and q is URI then add (?w ?q ?v) * rdfp8b: (?p owl:inverseOf ?q) (?v ?q ?w) where w is URI or BlankNode and q is URI then add (?w ?p ?v) * rdfp9: (?v rdf:type rdfs:Class) (?v owl:sameAs ?w) then add (?v rdfs:subClassOf ?w) * rdfp10: (?p rdf:type rdf:Property) (?p owl:sameAs ?q) then add (?p rdfs:subPropertyOf ?q) * * */ while (previousStatementCount != itsInferences.StatementCount) { previousStatementCount = itsInferences.StatementCount; foreach (Rule rule in rules) { itsInferences.Evaluate(rule); } } }