private GraphNet LoadPredicateGraph()
        {
            var gn = new PredicateNet("p:", new Uri("http://test.com/places/"), (uri, graph) => {
                graph.Add("p:name", "http://www.w3.org/2000/01/rdf-schema#domain", "p:Place");
                graph.Add("p:code", "http://www.w3.org/2000/01/rdf-schema#domain", "p:Place");
                graph.Add("p:flag", "http://www.w3.org/2000/01/rdf-schema#domain", "p:Country");
                graph.Add("p:nationalAnthem", "http://www.w3.org/2000/01/rdf-schema#domain", "p:Country");
                graph.Add("p:capitalCity", "http://www.w3.org/2000/01/rdf-schema#domain", "p:Country");
                graph.Add("p:mayor", "http://www.w3.org/2000/01/rdf-schema#domain", "p:City");
                graph.Add("p:Country", "http://www.w3.org/2000/01/rdf-schema#subClassof", "p:Place");
                graph.Add("p:City", "http://www.w3.org/2000/01/rdf-schema#subClassof", "p:Place");
                graph.Add("p:Town", "http://www.w3.org/2000/01/rdf-schema#subClassof", "p:Place");
            });

            gn.TrainFromQueries(
                "select * where { ?s a p:City . ?s p:mayor ?mayor }",
                "select * where { ?s a p:City . ?s p:code ?code }",
                "select * where { ?s a p:Country . ?s p:flag ?flag }",
                "select * where { ?s a p:Country . ?s p:nationalAnthem ?nationalAnthem }",
                "select distinct * where { ?s a p:Country . ?s p:name ?name }",
                "select distinct * where { ?s p:name ?name }",
                "select * where { ?s a p:Place . ?s p:code ?code }"
                );

            gn.Add("london", "a", "p:City");
            gn.Add("france", "a", "p:Country");
            gn.Add("farnham", "a", "p:Town");

            return(gn);
        }
Beispiel #2
0
        public void TestVocab()
        {
            //TODO: this is a bit nasty think about it (perhaps the method return nodes and then the graph does the adding??)
            var gn = new PredicateNet("p:", new Uri("http://test.com/places/"), (uri, graph) => {
                var net = graph as PredicateNet;
                graph.Add("p:name", "http://www.w3.org/2000/01/rdf-schema#domain", "p:Place");
                graph.Add("p:code", "http://www.w3.org/2000/01/rdf-schema#domain", "p:Place");
                graph.Add("p:flag", "http://www.w3.org/2000/01/rdf-schema#domain", "p:Country");
                graph.Add("p:mayor", "http://www.w3.org/2000/01/rdf-schema#domain", "p:City");
                graph.Add("p:Country", "http://www.w3.org/2000/01/rdf-schema#subClassof", "p:Place");
                graph.Add("p:City", "http://www.w3.org/2000/01/rdf-schema#subClassof", "p:Place");
                net.Add(net.GetPrefixNamespaceNode(), net.Node("has"), graph.Node("p:name"));
                net.Add(net.GetPrefixNamespaceNode(), net.Node("has"), graph.Node("p:code"));
                net.Add(net.GetPrefixNamespaceNode(), net.Node("has"), graph.Node("p:flag"));
                net.Add(net.GetPrefixNamespaceNode(), net.Node("has"), graph.Node("p:mayor"));
            });

            gn.MaxNumberOfPaths = 5;
            //gn.MaxPathLenght = 10;
            gn.TrainFromQueries(
                "select * where { ?s a p:City . ?s p:mayor ?mayor }",
                "select * where { ?x a p:City . ?x p:mayor 'ted' }",
                //TODO: this should not throw the prediction off "select * where { ?s a p:City . ?s p:name ?name }",
                "select * where { ?s a p:Country . ?s p:flag ?flag }",
                "select * where { ?x a p:Country . ?x p:flag 'xxx' }"
                );

            //var cityQuery = new Node("select *");
            var city = new UriNode("?x");

            city.UseEdgesAsInterface = false;
            //cityQuery.AddEdge("next", city, gn);
            city.AddEdge(new UriNode("a"), new UriNode("http://test.com/places/City"));
            Assert.AreEqual("mayor", gn.Predict(city));

            //var countryQuery = new Node("select *");
            var country = new UriNode("?x");

            country.UseEdgesAsInterface = false;
            //countryQuery.AddEdge("next", country, gn);
            country.AddEdge(new UriNode("a"), new UriNode("http://test.com/places/Country"));
            Assert.AreEqual("flag", gn.Predict(country));
        }