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 GetStatementEnumeratorIsEmptyForNewTripleStore() { TripleStore store = MakeNewTripleStore(); IEnumerator statementEnum = store.GetStatementEnumerator(); Assert.IsFalse(statementEnum.MoveNext(), "Enumerator has no first statement"); store.Clear(); }
public void GetStatementEnumeratorReturnsResourceStatementInstances() { TripleStore store = MakeNewTripleStore(); store.Add(new Statement(new BlankNode(), new UriRef("http://example.com/pred"), new UriRef("http://example.com/obj1"))); IEnumerator statementEnum = store.GetStatementEnumerator(); Assert.IsTrue(statementEnum.MoveNext(), "Enumerator has first statement"); Assert.IsTrue(statementEnum.Current is ResourceStatement, "Enumerator returns a ResourceStatement"); store.Clear(); }
public virtual void Replace(ConciseBoundedDescription description) { Resource internalSubjectResource = GetResourceDescribedBy(description); ArrayList statementsToRemove = new ArrayList(); IEnumerator statementEnumerator = itsAssertions.GetStatementEnumerator(); while (statementEnumerator.MoveNext()) { ResourceStatement statement = (ResourceStatement)statementEnumerator.Current; if (statement.GetSubject().Equals(internalSubjectResource)) { statementsToRemove.Add(statement); } } foreach (ResourceStatement statement in statementsToRemove) { itsAssertions.Remove(statement); } Add(description); }
public ArrayList GetSolutions(TripleStore store, QueryGroup group, Bindings bindings) { if (Explain) { Console.WriteLine("Solving " + group.GetType()); } if (group is QueryGroupOr) { if (Explain) { Console.WriteLine("Solving QueryGroupOr"); } ArrayList solutions = new ArrayList(); foreach (QueryGroup subgroup in ((QueryGroupOr)group).Groups) { solutions.AddRange(GetSolutions(store, subgroup, bindings)); } if (Explain) { Console.WriteLine("Have " + solutions.Count + " candidate solutions after or"); } return(solutions); } else if (group is QueryGroupAnd) { ArrayList solutions = new ArrayList(); solutions.Add(bindings); foreach (QueryGroup subgroup in ((QueryGroupAnd)group).Groups) { ArrayList filteredSolutions = new ArrayList(); foreach (Bindings tempBindings in solutions) { filteredSolutions.AddRange(GetSolutions(store, subgroup, tempBindings)); } solutions = filteredSolutions; if (Explain) { Console.WriteLine("Have " + solutions.Count + " candidate solutions after " + subgroup.GetType()); } } return(solutions); } else if (group is QueryGroupOptional) { if (Explain) { Console.WriteLine("Solving QueryGroupOptional"); } ArrayList augmentedSolutions = GetSolutions(store, ((QueryGroupOptional)group).Group, bindings); if (augmentedSolutions.Count == 0) { augmentedSolutions.Add(bindings); } return(augmentedSolutions); } else if (group is QueryGroupConstraints) { if (Explain) { Console.WriteLine("Solving QueryGroupConstraints"); } ArrayList solutions = new ArrayList(); foreach (Constraint constraint in ((QueryGroupConstraints)group).Constraints) { if (Explain) { Console.WriteLine("Testing solution against constraint {0}", constraint); } if (!constraint.SatisfiedBy(bindings)) { if (Explain) { Console.WriteLine("Failed to satisfy constraint"); } return(solutions); } } solutions.Add(bindings); return(solutions); } else if (group is QueryGroupPatterns) { if (Explain) { Console.WriteLine("Solving QueryGroupPatterns"); } ArrayList solutions = new ArrayList(); if (((QueryGroupPatterns)group).Patterns.Count == 0) { return(solutions); } Bindings answers = new Bindings(); Pattern firstGoal = ((QueryGroupPatterns)group).First(); Pattern newGoal = firstGoal.Substitute(bindings); IEnumerator statements = store.GetStatementEnumerator(); while (statements.MoveNext()) { ResourceStatement statement = (ResourceStatement)statements.Current; if (Explain) { Console.WriteLine("Trying for a binding for {0} with {1}", statement, newGoal); } answers = statement.Unify(newGoal, bindings, store); if (answers != null) { if (Explain) { Console.WriteLine("Got a binding for {0} with {1}", statement, newGoal); } if (((QueryGroupPatterns)group).Patterns.Count == 1) { if (Explain) { Console.WriteLine("Got a candidate solution {0}", answers); } solutions.Add(answers); } else { solutions.AddRange(GetSolutions(store, ((QueryGroupPatterns)group).Rest(), answers)); } } } return(solutions); } else { return(new ArrayList()); } }