public void TestFormulaWithList() { N3Writer instance = (N3Writer)CreateInstance(); BNode listId = new BNode(); BNode listTwoId = new BNode(); BNode listThreeId = new BNode(); instance.Add(new Statement(listId, Predicate.RdfFirst, (Entity)"A")); instance.Add(new Statement(listId, Predicate.RdfRest, listTwoId)); instance.Add(new Statement(listTwoId, Predicate.RdfFirst, (Entity)"B")); instance.Add(new Statement(listTwoId, Predicate.RdfRest, listThreeId)); instance.Add(new Statement(listThreeId, Predicate.RdfFirst, (Entity)"C")); instance.Add(new Statement(listThreeId, Predicate.RdfRest, Identifier.RdfNil)); BNode statementXId = new BNode(); BNode statementYId = new BNode(); instance.Add(new Statement(listId, "p", (Entity)"X", statementXId)); instance.Add(new Statement(listId, "p", (Entity)"Y", statementYId)); instance.Add(new Statement(statementXId, Predicate.LogImplies, statementYId)); instance.Close(); string expected = "{(<A> <B> <C>) <p> <X>.} => {(<A> <B> <C>) <p> <Y>.}."; Assert.AreEqual(expected, writer.ToString()); }
public void TestListWithFormulaElements() { N3Writer instance = (N3Writer)CreateInstance(); BNode statementXId = new BNode(); BNode statementYId = new BNode(); BNode statementZId = new BNode(); instance.Add(new Statement("S", "p", (Entity)"X", statementXId)); instance.Add(new Statement("S", "p", (Entity)"Y", statementYId)); instance.Add(new Statement("S", "p", (Entity)"Z", statementZId)); BNode listId = new BNode(); BNode listTwoId = new BNode(); BNode listThreeId = new BNode(); instance.Add(new Statement(listId, Predicate.RdfType, (Entity)"List")); instance.Add(new Statement(listId, Predicate.RdfFirst, statementXId)); instance.Add(new Statement(listId, Predicate.RdfRest, listTwoId)); instance.Add(new Statement(listTwoId, Predicate.RdfFirst, statementYId)); instance.Add(new Statement(listTwoId, Predicate.RdfRest, listThreeId)); instance.Add(new Statement(listThreeId, Predicate.RdfFirst, statementZId)); instance.Add(new Statement(listThreeId, Predicate.RdfRest, Identifier.RdfNil)); instance.Close(); string expected = "({<S> <p> <X>.}\n {<S> <p> <Y>.}\n {<S> <p> <Z>.}) a <List>."; Assert.AreEqual(expected, writer.ToString()); }
public void TestNamespaces() { N3Writer instance = (N3Writer)CreateInstance(); instance.Add(new Statement("http://example.org/A", Predicate.RdfType, (Entity)"X")); instance.Namespaces.AddNamespace("http://example.org/", "ex"); instance.Close(); string expected = "@prefix ex: <http://example.org/>.\nex:A a <X>."; Assert.AreEqual(expected, writer.ToString()); }
public void TestFormulaMultipleOccurences() { N3Writer instance = (N3Writer)CreateInstance(); BNode statementId = new BNode(); instance.Add(new Statement("S", "p", (Entity)"O", statementId)); instance.Add(new Statement("MyTheory", "contains", statementId)); instance.Add(new Statement(statementId, "is", (Entity)"True")); instance.Close(); string expected = "<MyTheory> <contains> {<S> <p> <O>.}.\n{<S> <p> <O>.} <is> <True>."; Assert.AreEqual(expected, writer.ToString()); }
public void TestListWithOneElement() { N3Writer instance = (N3Writer)CreateInstance(); BNode listId = new BNode(); instance.Add(new Statement(listId, Predicate.RdfType, (Entity)"List")); instance.Add(new Statement(listId, Predicate.RdfFirst, (Entity)"A")); instance.Add(new Statement(listId, Predicate.RdfRest, Identifier.RdfNil)); instance.Close(); string expected = "(<A>) a <List>."; Assert.AreEqual(expected, writer.ToString()); }
public void TestFormulaSingleOccurence() { N3Writer instance = (N3Writer)CreateInstance(); BNode statementXId = new BNode(); BNode statementYId = new BNode(); instance.Add(new Statement("S", "p", (Entity)"X", statementXId)); instance.Add(new Statement("S", "p", (Entity)"Y", statementYId)); instance.Add(new Statement(statementXId, Predicate.LogImplies, statementYId)); instance.Close(); string expected = "{<S> <p> <X>.} => {<S> <p> <Y>.}."; Assert.AreEqual(expected, writer.ToString()); }
public void TestFormulaMixedWithRegularStatements() { N3Writer instance = (N3Writer)CreateInstance(); BNode statementXId = new BNode(); BNode statementYId = new BNode(); instance.Add(new Statement("S", "b", (Entity)"B")); instance.Add(new Statement("S", "p", (Entity)"X", statementXId)); instance.Add(new Statement("S", "p", (Entity)"Y", statementYId)); instance.Add(new Statement(statementXId, Predicate.LogImplies, statementYId)); instance.Close(); string expected = "<S> <b> <B>.\n{<S> <p> <X>.} => {<S> <p> <Y>.}."; Assert.AreEqual(expected, writer.ToString()); }
public void TestFormulaWithMultipleStatementsSingleOccurence() { N3Writer instance = (N3Writer)CreateInstance(); BNode formulaId = new BNode(); BNode statementZId = new BNode(); instance.Add(new Statement("S", "p", (Entity)"X", formulaId)); instance.Add(new Statement("S", "p", (Entity)"Y", formulaId)); instance.Add(new Statement("S", "p", (Entity)"Z", statementZId)); instance.Add(new Statement(formulaId, Predicate.LogImplies, statementZId)); instance.Close(); string expected = "{\n <S> <p> <X>.\n <S> <p> <Y>.\n} => {<S> <p> <Z>.}."; Assert.AreEqual(expected, writer.ToString()); }
public void TestFormulaWithinFormula() { N3Writer instance = (N3Writer)CreateInstance(); BNode statementXId = new BNode(); BNode statementYId = new BNode(); BNode statementImplId = new BNode(); instance.Add(new Statement("S", "p", (Entity)"X", statementXId)); instance.Add(new Statement("S", "p", (Entity)"Y", statementYId)); instance.Add(new Statement(statementXId, Predicate.LogImplies, statementYId, statementImplId)); instance.Add(new Statement(statementImplId, Predicate.LogImplies, (Entity)"Truth")); instance.Close(); string expected = "{\n{<S> <p> <X>.}\n=>\n{<S> <p> <Y>.}.\n} => <Truth>."; Assert.AreEqual(expected, writer.ToString()); }
public void TestListWithThreeElementsWithLastUnbound() { N3Writer instance = (N3Writer)CreateInstance(); BNode listId = new BNode(); BNode listTwoId = new BNode(); BNode listThreeId = new BNode(); instance.Add(new Statement(listId, Predicate.RdfType, (Entity)"List")); instance.Add(new Statement(listId, Predicate.RdfFirst, (Entity)"A")); instance.Add(new Statement(listId, Predicate.RdfRest, listTwoId)); instance.Add(new Statement(listTwoId, Predicate.RdfFirst, (Entity)"B")); instance.Add(new Statement(listTwoId, Predicate.RdfRest, listThreeId)); instance.Add(new Statement(listThreeId, Predicate.RdfFirst, (Entity)"C")); instance.Close(); string expected = @"\(<A> <B> <C> _:bnode\d+\) a <List>."; Assert.That(writer.ToString(), Text.Matches(expected)); }
public void InteropSemWebGraphSource() { Graph g = new Graph(); //FileLoader.Load(g, "InferenceTest.ttl"); GraphSource source = new GraphSource(g); Console.WriteLine("Reading the input using SemWeb"); N3Reader reader = new N3Reader("InferenceTest.ttl"); reader.Select(source); Console.WriteLine(); Console.WriteLine("Outputting all Triples using N3Writer"); N3Writer writer = new N3Writer(Console.Out); source.Select(writer); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Outputting all Triples of the form ?s rdf:type ?type"); Statement template = new Statement(new Variable(), new Entity(RdfSpecsHelper.RdfType), new Variable()); source.Select(template, writer); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Outputting all Triples of the form ?s rdf:type ?car"); template = new Statement(new Variable(), new Entity(RdfSpecsHelper.RdfType), new Entity("http://example.org/vehicles/Car")); source.Select(template, writer); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Outputting all Triples for Cars and Planes"); SelectFilter filter = new SelectFilter(); filter.Predicates = new Entity[] { new Entity(RdfSpecsHelper.RdfType) }; filter.Objects = new Entity[] { new Entity("http://example.org/vehicles/Car"), new Entity("http://example.org/vehicles/Plane") }; source.Select(filter, writer); Console.WriteLine(); Console.WriteLine(); writer.Close(); }
public void InteropSemWebInMemoryStoreSource() { MicrosoftSqlStoreManager mssql = new MicrosoftSqlStoreManager("dotnetrdf_experimental", "sa", "20sQl08"); InMemoryStoreSource source = new InMemoryStoreSource(new SqlTripleStore(mssql)); N3Writer writer = new N3Writer(Console.Out); Console.WriteLine("Outputting all Triples of the form ?s rdf:type ?type"); Statement template = new Statement(new Variable(), new Entity(RdfSpecsHelper.RdfType), new Variable()); source.Select(template, writer); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Outputting all Triples of the form ?s rdf:type ?car"); template = new Statement(new Variable(), new Entity(RdfSpecsHelper.RdfType), new Entity("http://example.org/vehicles/Car")); source.Select(template, writer); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Outputting all Triples for Cars and Planes"); SelectFilter filter = new SelectFilter(); filter.Predicates = new Entity[] { new Entity(RdfSpecsHelper.RdfType) }; filter.Objects = new Entity[] { new Entity("http://example.org/vehicles/Car"), new Entity("http://example.org/vehicles/Plane") }; source.Select(filter, writer); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Outputting the Speeds of all Cards"); Variable car = new Variable("car"); Statement[] pattern = new Statement[] { new Statement(car, new Entity(RdfSpecsHelper.RdfType), new Entity("http://example.org/vehicles/Car")), new Statement(car, new Entity("http://example.org/vehicles/Speed"), new Variable("speed")) }; source.Query(pattern, new QueryOptions(), new SemWebResultsConsolePrinter()); Console.WriteLine(); writer.Close(); }