Beispiel #1
0
        public void RoundtripsDatetimeTypedLiterals(string dateTimeValue, string datatype)
        {
            var isValidDateTime    = DateTime.TryParse(dateTimeValue, null, DateTimeStyles.AdjustToUniversal, out DateTime parsedDateTime);
            var isDateTimeDatatype = datatype == XmlSpecsHelper.XmlSchemaDataTypeDateTime;

            if (isValidDateTime && isDateTimeDatatype)
            {
                using (var store = new TripleStore())
                {
                    var jsonLd = $@"
{{
    ""http://example.com/1"": {{
        ""@type"": ""{datatype}"",
        ""@value"": ""{dateTimeValue}""
    }}
}}
";
                    store.LoadFromString(jsonLd, new JsonLdParser());

                    var result = store.Graphs.Single().Triples.Single().Object.AsValuedNode().AsDateTime();

                    Assert.Equal(parsedDateTime, result);
                }
            }
        }
Beispiel #2
0
        public void SparqlPropertyPathEvaluationGraphInteraction()
        {
            String query = @"PREFIX ex: <http://www.example.org/schema#>
PREFIX in: <http://www.example.org/instance#>

SELECT ?x
FROM NAMED <http://example/1>
FROM NAMED <http://example/2>
WHERE
{
  GRAPH ?g { in:a ex:p1 / ex:p2 ?x . }
}";

            String data =
                @"<http://www.example.org/instance#a> <http://www.example.org/schema#p1> <http://www.example.org/instance#b> <http://example/1> .
<http://www.example.org/instance#b> <http://www.example.org/schema#p2> <http://www.example.org/instance#c> <http://example/2> .";

            TripleStore store = new TripleStore();

            store.LoadFromString(data, new NQuadsParser());
            var queryParser = new SparqlQueryParser();
            var q           = queryParser.ParseFromString(query);
            var processor   = new LeviathanQueryProcessor(store);

            SparqlResultSet results = processor.ProcessQuery(q) as SparqlResultSet;

            Assert.NotNull(results);
            Assert.Equal(SparqlResultsType.VariableBindings, results.ResultsType);
            Assert.Empty(results.Results);
        }
Beispiel #3
0
        public void SparqlPropertyPathEvaluationGraphInteraction()
        {
            String query = @"PREFIX ex: <http://www.example.org/schema#>
PREFIX in: <http://www.example.org/instance#>

SELECT ?x
FROM NAMED <http://example/1>
FROM NAMED <http://example/2>
WHERE
{
  GRAPH ?g { in:a ex:p1 / ex:p2 ?x . }
}";

            String data =
                @"<http://www.example.org/instance#a> <http://www.example.org/schema#p1> <http://www.example.org/instance#b> <http://example/1> .
<http://www.example.org/instance#b> <http://www.example.org/schema#p2> <http://www.example.org/instance#c> <http://example/2> .";

            TripleStore store = new TripleStore();

            store.LoadFromString(data, new NQuadsParser());

            SparqlResultSet results = store.ExecuteQuery(query) as SparqlResultSet;

            Assert.IsNotNull(results);
            Assert.AreEqual(SparqlResultsType.VariableBindings, results.ResultsType);
            Assert.AreEqual(0, results.Results.Count);
        }
        private void FixedQuery(string endpoint)
        {
            using (var originalStore = new TripleStore())
            {
                var expected = FixedQueryHelper.x(endpoint);

                if (expected == null)
                {
                    Assert.Inconclusive("Empty graph");
                }

                using (var actual = new TripleStore())
                {
                    actual.LoadFromString(
                        StringWriter.Write(expected, new FriendlyJsonLdWriter()),
                        new JsonLdParser());


                    if (!(actual.IsEmpty && expected.IsEmpty))
                    {
                        Assert.AreEqual(
                            Normalize(expected),
                            Normalize(actual.Graphs.Single()));
                    }
                }
            }
        }
        public void Setup()
        {
            TripleStore store = new TripleStore();

            store.LoadFromString(data);
            this._dataset   = new InMemoryQuadDataset(store, false);
            this._processor = new LeviathanQueryProcessor(this._dataset);
        }
        public void ParsingTrigRecommendationSyntax1()
        {
            const string data = "@prefix : <http://example.com/> . { :1 :p :o . }";

            var store = new TripleStore();

            store.LoadFromString(data, new TriGParser(TriGSyntax.Recommendation));

            Assert.Single(store.Graphs);
            Assert.Single(store.Triples);
        }
Beispiel #7
0
        public void RoundtripsDatetimeLiteralsInDiff(string dateTimeValue, string datatype)
        {
            using (var original = new TripleStore())
            {
                original.LoadFromString($@"<http://example.com/1> <http://example.com/1> ""{dateTimeValue}""^^<{datatype}>.");

                using (var target = new TripleStore())
                {
                    target.LoadFromString(StringWriter.Write(original, new JsonLdWriter()), new JsonLdParser());

                    Assert.True(original.Graphs.Single().Difference(target.Graphs.Single()).AreEqual);
                }
            }
        }
Beispiel #8
0
        public void RoundtripsDatetimeLiterals(string dateTimeValue, string datatype)
        {
            using (var store = new TripleStore())
            {
                var jsonLd = $@"
{{
    ""http://example.com/1"": {{
        ""@type"": ""{datatype}"",
        ""@value"": ""{dateTimeValue}""
    }}
}}
";
                store.LoadFromString(jsonLd, new JsonLdParser());

                var result = store.Graphs.Single().Triples.Single().Object.As <ILiteralNode>();

                Assert.Equal(dateTimeValue, result.Value);
                Assert.Equal(datatype, result.DataType.AbsoluteUri);
            }
        }
        public void JsonLDTestSuite(string name)
        {
            RdfXmlTestSuiteHelper.GetGraphs(name, out IGraph action, out IGraph expected);

            if (!expected.Equals(action))
            {
                Assert.Inconclusive();
            }

            var actual = new TripleStore();

            actual.LoadFromString(
                StringWriter.Write(action, new FriendlyJsonLdWriter()),
                new JsonLdParser());

            if (!(actual.IsEmpty && expected.IsEmpty))
            {
                Assert.AreEqual(
                    Normalize(expected),
                    Normalize(actual.Graphs.Single()));
            }
        }
        /// <summary>
        /// Converts rdf string to dotNetRdf graph.
        /// </summary>
        /// <param name="baseUri"></param>
        /// <param name="serializedModel">Literal string read from file.</param>
        /// <param name="rdfFormat"></param>
        /// <returns></returns>
        public IGraph DeserializeGraph(string baseUri, string serializedModel, RdfFormat rdfFormat)
        {
            // TODO: Handle 'Optional' properly
            var reader = RdfFormatsMapper.ToRdfReader(rdfFormat);

            try
            {
                if (reader is IRdfReader)
                {
                    var g = new Graph();
                    if (!String.IsNullOrEmpty(baseUri))
                    {
                        g.BaseUri = new Uri(baseUri);
                    }
                    g.LoadFromString(serializedModel, (IRdfReader)reader);
                    return(g);
                }
                if (reader is IStoreReader)
                {
                    var ts = new TripleStore();
                    ts.LoadFromString(serializedModel, (IStoreReader)reader);
                    var g = ts.Graphs[null];
                    if (!String.IsNullOrEmpty(baseUri))
                    {
                        g.BaseUri = new Uri(baseUri);
                    }
                    return(g);
                }
                return(null);
            }
            catch (IOException ex)
            {
                string msg = String.Format("Unable to parse serialized RDF from '%s' format.", rdfFormat.GetJenaName());
                throw new RdfSerializationException(msg, ex);
            }
        }