public void GetStatementEnumerator() { Node theSubject = new NodeStub("http://example.com/subj"); Arc thePredicate = new UriRef("http://example.com/pred"); Node theFirstObject = new UriRef("http://example.com/obj1"); Node theSecondObject = new UriRef("http://example.com/obj2"); Statement statement1 = new Statement(new BlankNode(), new UriRef("http://example.com/pred"), new UriRef("http://example.com/obj1")); Statement statement2 = new Statement(new BlankNode(), new UriRef("http://example.com/pred"), new UriRef("http://example.com/obj2")); TripleStore store = MakeNewTripleStore(); store.Add(statement1); store.Add(statement2); ResourceStatement resStatement1 = new ResourceStatement(store.GetResourceDenotedBy(statement1.GetSubject()), store.GetResourceDenotedBy(statement1.GetPredicate()), store.GetResourceDenotedBy(statement1.GetObject())); ResourceStatement resStatement2 = new ResourceStatement(store.GetResourceDenotedBy(statement2.GetSubject()), store.GetResourceDenotedBy(statement2.GetPredicate()), store.GetResourceDenotedBy(statement2.GetObject())); IEnumerator statementEnum = store.GetStatementEnumerator(); Assert.IsTrue(statementEnum.MoveNext(), "Enumerator has first statement"); ResourceStatement firstStatement = (ResourceStatement)statementEnum.Current; Assert.IsTrue(statementEnum.MoveNext(), "Enumerator has second statement"); ResourceStatement secondStatement = (ResourceStatement)statementEnum.Current; Assert.IsFalse(statementEnum.MoveNext()); Assert.IsTrue((firstStatement.Equals(resStatement1) && secondStatement.Equals(resStatement2)) || (firstStatement.Equals(resStatement2) && secondStatement.Equals(resStatement1)), "Statements have correct components"); store.Clear(); }
public void AddResourceStatementIncrementsStatementCount() { TripleStore store = MakeNewTripleStore(); Resource subjectResource = store.GetResourceDenotedBy(new UriRef("http://example.com/subj")); Resource predicateResource = store.GetResourceDenotedBy(new UriRef("http://example.com/pred")); Resource objectResource = store.GetResourceDenotedBy(new UriRef("http://example.com/obj")); store.Add(new ResourceStatement(subjectResource, predicateResource, objectResource)); Assert.AreEqual(1, store.StatementCount); store.Clear(); }
public void AddDenotationMakesResourceAccesibleViaDenotee() { TripleStore store = MakeNewTripleStore(); store.Add(new Statement(new UriRef("http://example.com/subj"), new UriRef("http://example.com/pred"), new UriRef("http://example.com/obj"))); Resource originalResource = store.GetResourceDenotedBy(new UriRef("http://example.com/subj")); store.AddDenotation(new UriRef("foo:bar"), originalResource); Assert.AreEqual(originalResource, store.GetResourceDenotedBy(new UriRef("foo:bar"))); store.Clear(); }
public void GetResourceDenotedByDoesNotChangeIsEmptyFlag() { TripleStore store = MakeNewTripleStore(); store.GetResourceDenotedBy(new UriRef("http://example.com/uri")); Assert.IsTrue(store.IsEmpty()); store.Clear(); }
public void ApplyConsequentStatements(Rule rule, TripleStore store) { ArrayList consequentStatements = new ArrayList(); foreach (Pattern pattern in rule.Consequents) { Resource subjectResource; Resource predicateResource; Resource objectResource; if (pattern.GetSubject() is Variable) { continue; } else { subjectResource = store.GetResourceDenotedBy((GraphMember)pattern.GetSubject()); } if (pattern.GetPredicate() is Variable) { continue; } else { predicateResource = store.GetResourceDenotedBy((GraphMember)pattern.GetPredicate()); } if (pattern.GetObject() is Variable) { continue; } else { objectResource = store.GetResourceDenotedBy((GraphMember)pattern.GetObject()); } consequentStatements.Add(new ResourceStatement(subjectResource, predicateResource, objectResource)); } foreach (ResourceStatement statement in consequentStatements) { store.Add(statement); } }
public void RemoveExistingTriple() { TripleStore store = MakeNewTripleStore(); BlankNode theSubjectNode = new BlankNode(); UriRef thePredicateNode = new UriRef("http://example.com/pred"); BlankNode theObjectNode = new BlankNode(); store.Add(new Statement(theSubjectNode, thePredicateNode, theObjectNode)); Resource theSubjectResource = store.GetResourceDenotedBy(theSubjectNode); Resource thePredicateResource = store.GetResourceDenotedBy(thePredicateNode); Resource theObjectResource = store.GetResourceDenotedBy(theObjectNode); //store.verbose = true; store.Remove(new ResourceStatement(theSubjectResource, thePredicateResource, theObjectResource)); TripleStoreVerifier verifier = new TripleStoreVerifier(); Assert.IsTrue(verifier.verify(store)); store.Clear(); }
public void AddTripleStoreWithIdenticalNodesDenotingDifferentResources() { UriRef node1 = new UriRef("any:node1"); UriRef node2 = new UriRef("any:node2"); UriRef node3 = new UriRef("any:node3"); UriRef predicate1 = new UriRef("any:predicate1"); UriRef predicate2 = new UriRef("any:predicate2"); Statement statement1 = new Statement(node1, predicate1, node2); Statement statement2 = new Statement(node1, predicate2, node3); TripleStore firstStore = MakeNewTripleStore(); firstStore.Add(statement1); Resource node1ResourceBefore = firstStore.GetResourceDenotedBy(node1); TripleStore secondStore = MakeNewTripleStore(); firstStore.Add(statement2); firstStore.Add(secondStore); Resource node1ResourceAfter = firstStore.GetResourceDenotedBy(node1); Assert.AreEqual(node1ResourceBefore, node1ResourceAfter); TripleStoreVerifier verifierFirst = new TripleStoreVerifier(); verifierFirst.expect("<any:node1> <any:predicate1> <any:node2> ."); verifierFirst.expect("<any:node1> <any:predicate2> <any:node3> ."); Assert.IsTrue(verifierFirst.verify(firstStore), "first knowledge base includes triples from second"); firstStore.Clear(); secondStore.Clear(); }
public void GetResourceDenotedByAlwaysReturnsSameResourceForSameGraphMember() { TripleStore store = MakeNewTripleStore(); Assert.AreEqual(store.GetResourceDenotedBy(new UriRef("http://example.com/uri")), store.GetResourceDenotedBy(new UriRef("http://example.com/uri")), "UriRef"); Assert.AreEqual(store.GetResourceDenotedBy(new PlainLiteral("squash")), store.GetResourceDenotedBy(new PlainLiteral("squash")), "Plain literal no language"); Assert.AreEqual(store.GetResourceDenotedBy(new PlainLiteral("squash", "de")), store.GetResourceDenotedBy(new PlainLiteral("squash", "de")), "Plain literal with language"); Assert.AreEqual(store.GetResourceDenotedBy(new TypedLiteral("squash", "http://example.com/type")), store.GetResourceDenotedBy(new TypedLiteral("squash", "http://example.com/type")), "Typed literal"); BlankNode blank = new BlankNode(); Assert.AreEqual(store.GetResourceDenotedBy(blank), store.GetResourceDenotedBy(blank), "Blank node"); store.Clear(); }
public void GetResourceDenotedReturnsSameResourceEvenAfterAllStatementsReferringToResourceHaveBeenRemoved() { TripleStore store = MakeNewTripleStore(); BlankNode theSubjectNode = new BlankNode(); UriRef thePredicateNode = new UriRef("http://example.com/pred"); BlankNode theObjectNode = new BlankNode(); store.Add(new Statement(theSubjectNode, thePredicateNode, theObjectNode)); Resource theSubjectResourceBefore = store.GetResourceDenotedBy(theSubjectNode); Resource thePredicateResourceBefore = store.GetResourceDenotedBy(thePredicateNode); Resource theObjectResourceBefore = store.GetResourceDenotedBy(theObjectNode); store.Remove(new ResourceStatement(theSubjectResourceBefore, thePredicateResourceBefore, theObjectResourceBefore)); Assert.AreEqual(theSubjectResourceBefore, store.GetResourceDenotedBy(theSubjectNode), "Subject resource should be the same"); Assert.AreEqual(thePredicateResourceBefore, store.GetResourceDenotedBy(thePredicateNode), "Predicate resource should be the same"); Assert.AreEqual(theObjectResourceBefore, store.GetResourceDenotedBy(theObjectNode), "Object resource should be the same"); store.Clear(); }
public void Process(Rule rule, TripleStore store) { Query query = new Query(); if (rule.Antecedents.Count == 0) { ApplyConsequentStatements(rule, store); return; } foreach (Pattern pattern in rule.Antecedents) { query.AddPattern(pattern); } foreach (Pattern pattern in rule.Consequents) { if (pattern.GetSubject() is Variable) { query.AddVariable(((Variable)pattern.GetSubject())); } if (pattern.GetPredicate() is Variable) { query.AddVariable(((Variable)pattern.GetPredicate())); } if (pattern.GetObject() is Variable) { query.AddVariable(((Variable)pattern.GetObject())); } } IEnumerator solutions = store.Solve(query); if (Explain) { ((BacktrackingQuerySolver)solutions).Explain = true; } ArrayList consequentStatements = new ArrayList(); while (solutions.MoveNext()) { QuerySolution solution = (QuerySolution)solutions.Current; foreach (Pattern pattern in rule.Consequents) { Resource subjectResource; Resource predicateResource; Resource objectResource; if (pattern.GetSubject() is Variable) { subjectResource = solution[((Variable)pattern.GetSubject()).Name]; } else { subjectResource = store.GetResourceDenotedBy((GraphMember)pattern.GetSubject()); } if (pattern.GetPredicate() is Variable) { predicateResource = solution[((Variable)pattern.GetPredicate()).Name]; } else { predicateResource = store.GetResourceDenotedBy((GraphMember)pattern.GetPredicate()); } if (pattern.GetObject() is Variable) { objectResource = solution[((Variable)pattern.GetObject()).Name]; } else { objectResource = store.GetResourceDenotedBy((GraphMember)pattern.GetObject()); } consequentStatements.Add(new ResourceStatement(subjectResource, predicateResource, objectResource)); } } foreach (ResourceStatement statement in consequentStatements) { store.Add(statement); } }