diff --git a/.gitignore b/.gitignore index 21fc7dfb..e3b1203e 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ Documentation/log.txt *.zip *.user **/.vs/** +**/.idea/** \ No newline at end of file diff --git a/Semiodesk.Trinity.sln b/Semiodesk.Trinity.sln index 429a0634..6d171be1 100644 --- a/Semiodesk.Trinity.sln +++ b/Semiodesk.Trinity.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29020.237 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.32228.430 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Trinity", "Trinity\Trinity.csproj", "{02896AA0-2FC6-4BF3-8F26-48F887DBFC6B}" EndProject @@ -29,6 +29,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{8F810E3F EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Trinity.Tests.Virtuoso", "tests\Trinity.Tests.Virtuoso\Trinity.Tests.Virtuoso.csproj", "{47A2749D-25BB-4C4D-BAFD-E0B02549A016}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Trinity.Fuseki", "Trinity.Fuseki\Trinity.Fuseki.csproj", "{049FDECC-2933-42F8-8F82-36BB2E22FC28}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Trinity.Tests.Fuseki", "tests\Trinity.Tests.Fuseki\Trinity.Tests.Fuseki.csproj", "{C5279E4A-5BCB-4FCD-ACAA-2800F4AE21A0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -92,6 +96,22 @@ Global {47A2749D-25BB-4C4D-BAFD-E0B02549A016}.Release|Any CPU.Build.0 = Release|Any CPU {47A2749D-25BB-4C4D-BAFD-E0B02549A016}.Release|x86.ActiveCfg = Release|Any CPU {47A2749D-25BB-4C4D-BAFD-E0B02549A016}.Release|x86.Build.0 = Release|Any CPU + {049FDECC-2933-42F8-8F82-36BB2E22FC28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {049FDECC-2933-42F8-8F82-36BB2E22FC28}.Debug|Any CPU.Build.0 = Debug|Any CPU + {049FDECC-2933-42F8-8F82-36BB2E22FC28}.Debug|x86.ActiveCfg = Debug|Any CPU + {049FDECC-2933-42F8-8F82-36BB2E22FC28}.Debug|x86.Build.0 = Debug|Any CPU + {049FDECC-2933-42F8-8F82-36BB2E22FC28}.Release|Any CPU.ActiveCfg = Release|Any CPU + {049FDECC-2933-42F8-8F82-36BB2E22FC28}.Release|Any CPU.Build.0 = Release|Any CPU + {049FDECC-2933-42F8-8F82-36BB2E22FC28}.Release|x86.ActiveCfg = Release|Any CPU + {049FDECC-2933-42F8-8F82-36BB2E22FC28}.Release|x86.Build.0 = Release|Any CPU + {C5279E4A-5BCB-4FCD-ACAA-2800F4AE21A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C5279E4A-5BCB-4FCD-ACAA-2800F4AE21A0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C5279E4A-5BCB-4FCD-ACAA-2800F4AE21A0}.Debug|x86.ActiveCfg = Debug|Any CPU + {C5279E4A-5BCB-4FCD-ACAA-2800F4AE21A0}.Debug|x86.Build.0 = Debug|Any CPU + {C5279E4A-5BCB-4FCD-ACAA-2800F4AE21A0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C5279E4A-5BCB-4FCD-ACAA-2800F4AE21A0}.Release|Any CPU.Build.0 = Release|Any CPU + {C5279E4A-5BCB-4FCD-ACAA-2800F4AE21A0}.Release|x86.ActiveCfg = Release|Any CPU + {C5279E4A-5BCB-4FCD-ACAA-2800F4AE21A0}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -99,6 +119,7 @@ Global GlobalSection(NestedProjects) = preSolution {5E1FCE3C-9436-44F8-8DB6-18F6282DE70C} = {8F810E3F-1005-4D95-BF82-E903B9DF4F5E} {47A2749D-25BB-4C4D-BAFD-E0B02549A016} = {8F810E3F-1005-4D95-BF82-E903B9DF4F5E} + {C5279E4A-5BCB-4FCD-ACAA-2800F4AE21A0} = {8F810E3F-1005-4D95-BF82-E903B9DF4F5E} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {01F0E2D7-A253-4F8E-9D8D-8C6EFF35CCF5} diff --git a/Trinity.Fuseki/FusekiSparqlQueryResult.cs b/Trinity.Fuseki/FusekiSparqlQueryResult.cs new file mode 100644 index 00000000..a421ace2 --- /dev/null +++ b/Trinity.Fuseki/FusekiSparqlQueryResult.cs @@ -0,0 +1,74 @@ +// LICENSE: +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +// AUTHORS: +// +// Moritz Eberl +// Sebastian Faubel +// +// Copyright (c) Semiodesk GmbH 2022 + +using VDS.RDF.Query; +using VDS.RDF; + +namespace Semiodesk.Trinity.Store.Fuseki +{ + /// + /// The results returned from a SPARQL query. + /// + internal class FusekiSparqlQueryResult : dotNetRDFQueryResult + { + #region Members + + #endregion + + #region Constructors + + /// + /// Internal constructor which parses the results returned from a given query. + /// + /// The executed query. + /// + /// the results + internal FusekiSparqlQueryResult(FusekiStore store, ISparqlQuery query, SparqlResultSet resultSet) : base(store, query, resultSet) + { + + } + + /// + /// Internal constructor which parses the results returned from a given query. + /// + /// The executed query. + /// + /// the results + internal FusekiSparqlQueryResult(FusekiStore store, ISparqlQuery query, IGraph graph) : base(store, query, graph) + { + + } + + #endregion + + #region Methods + + #endregion + + } + +} diff --git a/Trinity.Fuseki/FusekiStore.cs b/Trinity.Fuseki/FusekiStore.cs new file mode 100644 index 00000000..580d0a97 --- /dev/null +++ b/Trinity.Fuseki/FusekiStore.cs @@ -0,0 +1,542 @@ +// LICENSE: +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +// AUTHORS: +// +// Moritz Eberl +// Sebastian Faubel +// +// Copyright (c) Semiodesk GmbH 2022 + +using System; +using System.Collections.Generic; +using System.Linq; +using System.IO; +using VDS.RDF.Parsing; +using VDS.RDF; +using Semiodesk.Trinity.Extensions; +using VDS.RDF.Storage; +using VDS.RDF.Query; +using VDS.RDF.Update; +using VDS.RDF.Parsing.Handlers; + +namespace Semiodesk.Trinity.Store.Fuseki +{ + /// + /// This class is the implementation of the IStorage inteface for the Fuseki Database. + /// It provides the backend specific implementation of the storage management functions. + /// + public class FusekiStore : StoreBase + { + #region Members + + SparqlUpdateParser _parser; + + /// + /// Handle to the Virtuoso connection. + /// + protected FusekiConnector Connector; + + /// + /// The host of the storage service. + /// + public string Hostname { get; protected set; } + + /// + /// The username used for establishing the connection. + /// + private string Dataset { get; set; } + + + private bool _isDisposed = false; + + #endregion + + #region Constructors + + + /// + /// Creates a new connection to the Virtuoso storage. + /// + /// The host of the storage service. + /// The service port on the storage service host. + /// Username used to connect to storage. + /// Password needed to connect to storage. + public FusekiStore(string host, string dataset, string username = null, string password = null) + { + Hostname = host; + Dataset = dataset; + Connector = new FusekiConnector($"{Hostname}/{dataset}/data"); + if( username != null || password != null ) + Connector.SetCredentials(username, password); + + _parser = new SparqlUpdateParser(); + } + + #endregion + + #region Methods + + + [Obsolete("It is not necessary to create models explicitly. Use GetModel() instead, if the model does not exist, it will be created implicitly.")] + public override IModel CreateModel(Uri uri) + { + return GetModel(uri); + } + + public override void RemoveModel(Uri uri) + { + if (!Connector.DeleteSupported) + throw new NotSupportedException("This store does not support the deletion of graphs."); + + Connector.DeleteGraph(uri); + } + + [Obsolete("This method does not list empty models. At the moment you should just call GetModel() and test for IsEmpty()")] + public override bool ContainsModel(Uri uri) + { + if (uri != null) + { + Connector.HasGraph(uri); + + } + + return false; + } + + [Obsolete("This method does not list empty models. At the moment you should just call GetModel() and test for IsEmpty()")] + public override bool ContainsModel(IModel model) + { + return ContainsModel(model.Uri); + } + + /// + /// Updates the properties of a resource in the backing RDF store. + /// + /// Resource that is to be updated in the backing store. + /// Uri of the model where the resource will be updated + /// Transaction associated with this action. + /// Set this to true to update only mapped properties. + public override void UpdateResource(Resource resource, Uri modelUri, ITransaction transaction = null, bool ignoreUnmappedProperties = false) + { + string updateString; + + if (resource.IsNew) + { + updateString = string.Format(@" + INSERT DATA {{ GRAPH <{0}> {{ {1} }} }} ", + modelUri.OriginalString, + SparqlSerializer.SerializeResource(resource, ignoreUnmappedProperties)); + } + else + { + updateString = string.Format(@" + WITH <{0}> + DELETE {{ {1} ?p ?o. }} + INSERT {{ {2} }} + WHERE {{ OPTIONAL {{ {1} ?p ?o. }} }} ", + modelUri.OriginalString, + SparqlSerializer.SerializeUri(resource.Uri), + SparqlSerializer.SerializeResource(resource, ignoreUnmappedProperties)); + } + + ExecuteNonQuery(new SparqlUpdate(updateString), transaction); + + resource.IsNew = false; + resource.IsSynchronized = true; + } + + /// + /// Executes a query on the store which does not expect a result. + /// + /// The update query + /// An associated transaction + public override void ExecuteNonQuery(ISparqlUpdate query, ITransaction transaction = null) + { + string q = query.ToString(); + + Log?.Invoke(q); + + //SparqlUpdateCommandSet cmds = _parser.ParseFromString(q); + + Connector.Update(q); + } + + /// + /// Executes a SparqlQuery on the store. + /// + /// + /// + /// + public override ISparqlQueryResult ExecuteQuery(ISparqlQuery query, ITransaction transaction = null) + { + string q = query.ToString(); + + object results = ExecuteQuery(q); + + if (results is IGraph) + { + return new dotNetRDFQueryResult(this, query, results as IGraph); + } + else if (results is SparqlResultSet) + { + return new dotNetRDFQueryResult(this, query, results as SparqlResultSet); + } + + return null; + } + + /// + /// This method queries the dotNetRdf store directly. + /// + /// + /// + public override object ExecuteQuery(string query) + { + Log?.Invoke(query); + return Connector.Query(query); + } + + /// + /// Gets a handle to a model in the store. + /// + /// Uri of the model. + /// + public override IModel GetModel(Uri uri) + { + return new Model(this, uri.ToUriRef()); + } + + /// + /// Indicates if the store is ready to be queried. + /// + public override bool IsReady { get; protected set; } = true; + + /// + /// Lists all models in the store. + /// + /// All handles to existing models. + public override IEnumerable ListModels() + { + foreach (var graph in Connector.ListGraphs()) + { + yield return new Model(this, new UriRef(graph)); + } + } + + /// + /// Try parse RDF from a given text reader into the store. + /// + /// The text reader to read from. + /// The graph to store the read triples. + /// RDF format to be read. + public static void TryParse(TextReader reader, IGraph graph, RdfSerializationFormat format) + { + switch (format) + { + case RdfSerializationFormat.N3: + new Notation3Parser().Load(graph, reader); break; + + case RdfSerializationFormat.NTriples: + new NTriplesParser().Load(graph, reader); break; + + + case RdfSerializationFormat.NQuads: + new NQuadsParser().Load(new GraphHandler(graph), reader); break; + + + case RdfSerializationFormat.Turtle: + new TurtleParser().Load(graph, reader); break; + + case RdfSerializationFormat.Json: + new RdfJsonParser().Load(graph, reader); break; + + case RdfSerializationFormat.JsonLd: + new JsonLdParser().Load(new GraphHandler(graph), reader); break; + + + default: + case RdfSerializationFormat.RdfXml: + new RdfXmlParser().Load(graph, reader); break; + } + } + + /// + /// Loads a serialized graph from the given String into the current store. See allowed formats. + /// + /// String containing a serialized graph + /// Uri of the graph in this store + /// Allowed formats + /// Pass false if you want to overwrite the existing data. True if you want to add the new data to the existing. + /// + public override Uri Read(string content, Uri graphUri, RdfSerializationFormat format, bool update) + { + var exists = Connector.HasGraph(graphUri); + using (StringReader reader = new StringReader(content)) + { + IGraph graph = new Graph(); + + TryParse(reader, graph, format); + + graph.BaseUri = graphUri; + + if (!update && exists) + { + Connector.DeleteGraph(graphUri); + } + + Connector.SaveGraph(graph); + + return graphUri; + } + } + + /// + /// Loads a serialized graph from the given stream into the current store. See allowed formats. + /// + /// Stream containing a serialized graph + /// Uri of the graph in this store + /// Allowed formats + /// Pass false if you want to overwrite the existing data. True if you want to add the new data to the existing. + /// + public override Uri Read(Stream stream, Uri graphUri, RdfSerializationFormat format, bool update, bool leaveOpen = false) + { + var exists = Connector.HasGraph(graphUri); + using (TextReader reader = new StreamReader(stream)) + { + IGraph graph = new Graph(); + + TryParse(reader, graph, format); + + graph.BaseUri = graphUri; + + if (!update && exists) + { + Connector.DeleteGraph(graphUri); + } + + Connector.SaveGraph(graph); + + if (!leaveOpen) + stream.Close(); + + return graphUri; + } + + } + + /// + /// Loads a serialized graph from the given location into the current store. See allowed formats. + /// + /// Uri of the graph in this store + /// Location + /// Allowed formats + /// Pass false if you want to overwrite the existing data. True if you want to add the new data to the existing. + /// + public override Uri Read(Uri graphUri, Uri url, RdfSerializationFormat format, bool update) + { + IGraph graph = null; + var exists = Connector.HasGraph(graphUri); + + if (url.AbsoluteUri.StartsWith("file:")) + { + string path; + + if (url.IsAbsoluteUri) + { + path = url.LocalPath; + } + else + { + path = Path.Combine(Directory.GetCurrentDirectory(), url.OriginalString.Substring(5)); + } + + if (graphUri != null) + { + if (format == RdfSerializationFormat.Trig) + { + TripleStore s = new TripleStore(); + s.LoadFromFile(path, new TriGParser()); + + foreach (Graph g in s.Graphs) + { + if (!update && exists) + { + Connector.DeleteGraph(graphUri); + } + + Connector.SaveGraph(g); + } + } + else + { + graph = new Graph(); + graph.LoadFromFile(path); + graph.BaseUri = graphUri; + } + } + } + else if (url.Scheme == "http") + { + graph = new Graph(); + + UriLoader.Load(graph, url); + + graph.BaseUri = graphUri; + } + + if (graph != null) + { + if (!update && exists) + { + Connector.DeleteGraph(graphUri); + } + + Connector.SaveGraph(graph); + + return graphUri; + } + + return null; + } + + /// + /// Writes a serialized graph to the given stream. See allowed formats. + /// + /// Stream to which the content should be written. + /// Uri fo the graph in this store. + /// Allowed formats. + /// Defines namespace to prefix mappings for the output. + /// Base URI for shortening URIs in formats that support it. + /// Indicates if the stream should be left open after writing completes. + /// + public override void Write(Stream stream, Uri graphUri, RdfSerializationFormat format, INamespaceMap namespaces = null, Uri baseUri = null, bool leaveOpen = false) + { + if (Connector.HasGraph(graphUri)) + { + IGraph graph = new Graph(); + Connector.LoadGraph(graph, graphUri); + + if (namespaces != null) + { + graph.NamespaceMap.ImportNamespaces(namespaces); + } + + if (baseUri != null) + { + graph.BaseUri = baseUri; + } + + Write(stream, graph, format, leaveOpen); + } + } + + /// + /// Writes a serialized graph to the given stream. See allowed formats. + /// + /// Stream to which the content should be written. + /// Uri fo the graph in this store + /// A RDF format writer. + /// Indicates if the stream should be left open after writing completes. + /// + public override void Write(Stream stream, Uri graphUri, IRdfWriter formatWriter, bool leaveOpen = false) + { + if (Connector.HasGraph(graphUri)) + { + IGraph graph = new Graph(); + Connector.LoadGraph(graph, graphUri); + + Write(stream, graph, formatWriter, leaveOpen); + } + } + + /// + /// + /// + /// + /// + public override ITransaction BeginTransaction(System.Data.IsolationLevel isolationLevel) + { + return null; + } + + /// + /// Creates a model group which allows for queries to be made on multiple models at once. + /// + /// + /// + public override IModelGroup CreateModelGroup(params Uri[] models) + { + List modelList = new List(); + + foreach (var x in models) + { + modelList.Add(GetModel(x)); + } + + return new ModelGroup(this, modelList); + } + + /// + /// Creates a model group which allows for queries to be made on multiple models at once. + /// + /// + /// + public new IModelGroup CreateModelGroup(params IModel[] models) + { + List modelList = new List(); + + // This approach might seem a bit redundant, but we want to make sure to get the model from the right store. + foreach (var x in models) + { + this.GetModel(x.Uri); + } + + return new ModelGroup(this, modelList); + } + + /// + /// Closes the store. It is not usable after this call. + /// + public override void Dispose() + { + IsReady = false; + Connector.Dispose(); + } + + /// + /// Gets a SPARQL query which is used to retrieve all triples about a subject that is + /// either referenced using a URI or blank node. + /// + /// The graph to be queried. + /// The subject to be described. + /// An instance of ISparqlQuery + public override ISparqlQuery GetDescribeQuery(Uri modelUri, Uri subjectUri) + { + ISparqlQuery query = new SparqlQuery("DESCRIBE ?s FROM @model WHERE { ?s ?p ?o . VALUES ?s { @subject } }"); + query.Bind("@model", modelUri); + query.Bind("@subject", subjectUri); + + return query; + } + + #endregion + } +} diff --git a/Trinity.Fuseki/FusekiStoreProvider.cs b/Trinity.Fuseki/FusekiStoreProvider.cs new file mode 100644 index 00000000..8137dddc --- /dev/null +++ b/Trinity.Fuseki/FusekiStoreProvider.cs @@ -0,0 +1,91 @@ +// LICENSE: +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +// AUTHORS: +// +// Moritz Eberl +// Sebastian Faubel +// +// Copyright (c) Semiodesk GmbH 2022 + + +using System.Collections.Generic; +using System.Composition; + + +namespace Semiodesk.Trinity.Store.Fuseki +{ + + [Export(typeof(StoreProvider))] + + public class FusekiStoreProvider : StoreProvider + { + public FusekiStoreProvider() + { + Name = "fuseki"; + } + + public override IStore GetStore(Dictionary configurationDictionary ) + { + string hostKey = "host"; + string host = "http://localhost:3030/"; + + if (configurationDictionary.ContainsKey(hostKey)) + { + host = configurationDictionary[hostKey]; + } + + string datasetKey = "dataset"; + string dataset = "dataset"; + + if (configurationDictionary.ContainsKey(datasetKey)) + { + dataset = configurationDictionary[datasetKey]; + } + + string userKey = "uid"; + string user = null; + + if (configurationDictionary.ContainsKey(userKey)) + { + user = configurationDictionary["uid"]; + } + + + string passwordKey = "pw"; + string password = null; + + if (configurationDictionary.ContainsKey(passwordKey)) + { + password = configurationDictionary[passwordKey]; + } + + if (string.IsNullOrEmpty(host)) + { + return null; + } + + + FusekiStore store = new FusekiStore(host, dataset, user, password); + + return store; + } + } +} diff --git a/Trinity.Fuseki/Properties/AssemblyInfo.cs b/Trinity.Fuseki/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..12108b94 --- /dev/null +++ b/Trinity.Fuseki/Properties/AssemblyInfo.cs @@ -0,0 +1,14 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("5780ed96-ed98-4676-b10d-a4d0b1fc3cb9")] + + diff --git a/Trinity.Fuseki/Trinity.Fuseki.csproj b/Trinity.Fuseki/Trinity.Fuseki.csproj new file mode 100644 index 00000000..7a1a26e5 --- /dev/null +++ b/Trinity.Fuseki/Trinity.Fuseki.csproj @@ -0,0 +1,68 @@ + + + + netstandard2.0 + Semiodesk.Trinity.Virtuoso + Copyright © Semiodesk GmbH 2015-2020 + This library allows Semiodesk.Trinity to use the OpenLink Virtuoso store directly through the ODBC interface. + Semiodesk GmbH + 1.0.3.50 + 1.0.3.30 + 1.0.3.30 + Semiodesk.Trinity.Fuseki + Semiodesk.Trinity.Store.Fuseki + true + + + + + ..\Build\$(Configuration)\stores\virtuoso + true + + https://trinity-rdf.net + trinity-logo.png + https://github.com/semiodesk/trinity-rdf + RDF SPARQL Database Semantic Object Mapping Linked Data Virtuoso + true + + + + + + + + + + + + + + + + + + + + + Dependencies\OpenLink.Data.Virtuoso.dll + true + + + + + + $(TargetsForTfmSpecificContentInPackage);CustomContentTarget + MIT + git + + + + + + lib/netstandard2.0 + + + + + + \ No newline at end of file diff --git a/Trinity.Virtuoso/Trinity.Virtuoso.csproj b/Trinity.Virtuoso/Trinity.Virtuoso.csproj index 2850dd77..d5fa32e9 100644 --- a/Trinity.Virtuoso/Trinity.Virtuoso.csproj +++ b/Trinity.Virtuoso/Trinity.Virtuoso.csproj @@ -1,71 +1,67 @@ - - - - netstandard2.0 - Semiodesk.Trinity.Virtuoso - Copyright © Semiodesk GmbH 2015-2020 - This library allows Semiodesk.Trinity to use the OpenLink Virtuoso store directly through the ODBC interface. - Semiodesk GmbH - 1.0.3.50 - 1.0.3.30 - 1.0.3.30 - Semiodesk.Trinity.Virtuoso - Semiodesk.Trinity.Store.Virtuoso - true - - - - - ..\Build\$(Configuration)\stores\virtuoso - true - - https://trinity-rdf.net - trinity-logo.png - https://github.com/semiodesk/trinity-rdf - RDF SPARQL Database Semantic Object Mapping Linked Data Virtuoso - true - - - + + + + netstandard2.0 + Semiodesk.Trinity.Virtuoso + Copyright © Semiodesk GmbH 2015-2020 + This library allows Semiodesk.Trinity to use the OpenLink Virtuoso store directly through the ODBC interface. + Semiodesk GmbH + 1.0.3.50 + 1.0.3.30 + 1.0.3.30 + Semiodesk.Trinity.Virtuoso + Semiodesk.Trinity.Store.Virtuoso + true + + + + + ..\Build\$(Configuration)\stores\virtuoso + true + + https://trinity-rdf.net + trinity-logo.png + https://github.com/semiodesk/trinity-rdf + RDF SPARQL Database Semantic Object Mapping Linked Data Virtuoso + true + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + Dependencies\OpenLink.Data.Virtuoso.dll true - - - - - $(TargetsForTfmSpecificContentInPackage);CustomContentTarget - MIT - git - - - - - - lib/netstandard2.0 - - - - - + + + + + $(TargetsForTfmSpecificContentInPackage);CustomContentTarget + MIT + git + + + + + + lib/netstandard2.0 + + + + + \ No newline at end of file diff --git a/Trinity/Query/SparqlSerializer.cs b/Trinity/Query/SparqlSerializer.cs index 0a126ee3..b0b85e2f 100644 --- a/Trinity/Query/SparqlSerializer.cs +++ b/Trinity/Query/SparqlSerializer.cs @@ -273,9 +273,9 @@ public static string SerializeCount(IModel model, ISparqlQuery query) StringBuilder queryBuilder = new StringBuilder(); - queryBuilder.Append("SELECT COUNT(DISTINCT "); + queryBuilder.Append("SELECT ( COUNT(DISTINCT "); queryBuilder.Append(variable); - queryBuilder.Append(") AS ?count "); + queryBuilder.Append(") AS ?count )"); queryBuilder.Append(from); queryBuilder.Append(" WHERE { "); queryBuilder.Append(where); diff --git a/Trinity/Stores/SparqlEndpoint/SparqlEndpointStore.cs b/Trinity/Stores/SparqlEndpoint/SparqlEndpointStore.cs index 4c5b10a4..e3d9c1e2 100644 --- a/Trinity/Stores/SparqlEndpoint/SparqlEndpointStore.cs +++ b/Trinity/Stores/SparqlEndpoint/SparqlEndpointStore.cs @@ -68,11 +68,12 @@ public bool IsReady #region Constructor - public SparqlEndpointStore(Uri endpointUri, IWebProxy proxy = null, NetworkCredential credentials = null) + public SparqlEndpointStore(Uri endpointUri, IWebProxy proxy = null, NetworkCredential credential = null) { _endpoint = new SparqlRemoteEndpoint(endpointUri); + _endpoint.Proxy = proxy; - _endpoint.Credentials = credentials; + _endpoint.Credentials = credential; } #endregion diff --git a/Trinity/Stores/StoreBase.cs b/Trinity/Stores/StoreBase.cs index 6a9e0117..c24118a9 100644 --- a/Trinity/Stores/StoreBase.cs +++ b/Trinity/Stores/StoreBase.cs @@ -38,7 +38,7 @@ namespace Semiodesk.Trinity { /// /// This class encapsulates the functionality of an abstract triple store. Cannot be used directly. - /// Use StoreFactory to get a concret implementation. + /// Use StoreFactory to get a concrete implementation. /// public abstract class StoreBase : IStore { @@ -105,6 +105,16 @@ public virtual bool ContainsModel(IModel model) /// public abstract ISparqlQueryResult ExecuteQuery(ISparqlQuery query, ITransaction transaction = null); + /// + /// Executes a string query directly on the store. + /// + /// SPARQL query to be executed. + /// A native return value is possible here. + public virtual object ExecuteQuery(string query) + { + return null; + } + /// /// Executes a query on the store which does not expect a result. /// diff --git a/Trinity/Stores/StoreFactory.cs b/Trinity/Stores/StoreFactory.cs index 05658afa..cdb62d28 100644 --- a/Trinity/Stores/StoreFactory.cs +++ b/Trinity/Stores/StoreFactory.cs @@ -33,7 +33,6 @@ using Semiodesk.Trinity.Store; using System.Configuration; using System.Reflection; -using System.Net; #if NETSTANDARD2_0 using System.Composition.Hosting; #elif !NET35 @@ -161,29 +160,6 @@ public static IStore CreateSparqlEndpointStore(Uri url) return CreateStore($"provider=sparqlendpoint;endpoint={url.AbsoluteUri}"); } - /// - /// Creates a SPARQL protocol endpoint store. - /// - /// URL of the SPARQL endpoint. - /// Endpoint credentials - /// - public static IStore CreateSparqlEndpointStore(Uri url, NetworkCredential credentials) - { - return new SparqlEndpointStore(url, null, credentials); - } - - /// - /// Creates a SPARQL protocol endpoint store. - /// - /// URL of the SPARQL endpoint. - /// Proxy settings to use for the HTTP connection. - /// Endpoint credentials - /// - public static IStore CreateSparqlEndpointStore(Uri url, IWebProxy proxy, NetworkCredential credentials) - { - return new SparqlEndpointStore(url, proxy, credentials); - } - /// /// Loads a store provider. /// diff --git a/Trinity/Stores/dotNetRDF/dotNetRDFQueryResult.cs b/Trinity/Stores/dotNetRDF/dotNetRDFQueryResult.cs index e4e619a7..bdb7262e 100644 --- a/Trinity/Stores/dotNetRDF/dotNetRDFQueryResult.cs +++ b/Trinity/Stores/dotNetRDF/dotNetRDFQueryResult.cs @@ -37,7 +37,7 @@ namespace Semiodesk.Trinity.Store { - internal class dotNetRDFQueryResult : ISparqlQueryResult + public class dotNetRDFQueryResult : ISparqlQueryResult { #region Members @@ -49,13 +49,13 @@ internal class dotNetRDFQueryResult : ISparqlQueryResult private SparqlResultSet _queryResults; - private dotNetRDFStore _store; + private StoreBase _store; #endregion #region Constructor - public dotNetRDFQueryResult(dotNetRDFStore store, ISparqlQuery query, SparqlResultSet resultSet) + public dotNetRDFQueryResult(StoreBase store, ISparqlQuery query, SparqlResultSet resultSet) { string s = null; string p = null; @@ -79,7 +79,7 @@ public dotNetRDFQueryResult(dotNetRDFStore store, ISparqlQuery query, SparqlResu _store = store; } - public dotNetRDFQueryResult(dotNetRDFStore store, ISparqlQuery query, IGraph graph) + public dotNetRDFQueryResult(StoreBase store, ISparqlQuery query, IGraph graph) { _query = query; _tripleProvider = new GraphTripleProvider(graph); @@ -429,8 +429,6 @@ public virtual int Count() SparqlQuery query = new SparqlQuery(countQuery); - // TODO: Apply inferencing if enabled. - object result = _store.ExecuteQuery(query.ToString()); if (result is SparqlResultSet) diff --git a/Trinity/Stores/dotNetRDF/dotNetRDFStore.cs b/Trinity/Stores/dotNetRDF/dotNetRDFStore.cs index eddd9f21..e6d3aba1 100644 --- a/Trinity/Stores/dotNetRDF/dotNetRDFStore.cs +++ b/Trinity/Stores/dotNetRDF/dotNetRDFStore.cs @@ -179,7 +179,7 @@ public override ISparqlQueryResult ExecuteQuery(ISparqlQuery query, ITransaction /// /// /// - public object ExecuteQuery(string query) + public override object ExecuteQuery(string query) { Log?.Invoke(query); diff --git a/Trinity/Trinity.csproj b/Trinity/Trinity.csproj index fe6e589f..b04bae05 100644 --- a/Trinity/Trinity.csproj +++ b/Trinity/Trinity.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net40 + netstandard2.0 Semiodesk.Trinity Copyright © Semiodesk GmbH 2015-2020 Enterprise ready object mapper for developing RDF knowledge graph applications with .NET @@ -70,9 +70,7 @@ - - @@ -95,32 +93,10 @@ - - - - - - - - - - - - - - - - - - ..\Dependencies\Net35\dotNetRDF.dll - - - - @@ -128,10 +104,5 @@ - - - 4.5.0 - - diff --git a/tests/Trinity.Tests.Fuseki/ModelGroupTest.cs b/tests/Trinity.Tests.Fuseki/ModelGroupTest.cs new file mode 100644 index 00000000..b58b2b87 --- /dev/null +++ b/tests/Trinity.Tests.Fuseki/ModelGroupTest.cs @@ -0,0 +1,190 @@ +// LICENSE: +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +// AUTHORS: +// +// Moritz Eberl +// Sebastian Faubel +// +// Copyright (c) Semiodesk GmbH 2015-2019 + +using NUnit.Framework; +using Semiodesk.Trinity.Ontologies; +using System; +using System.Linq; + +namespace Semiodesk.Trinity.Test.Fuseki +{ + [TestFixture] + public class ModelGroupTest : SetupClass + { + protected IStore Store; + + protected IModel Model = null; + + protected IModel Model2 = null; + + [SetUp] + public void SetUp() + { + string connectionString = SetupClass.ConnectionString; + + Store = StoreFactory.CreateStore(string.Format("{0};rule=urn:semiodesk/test/ruleset", connectionString)); + + Model = Store.GetModel(new Uri("http://example.org/TestModel")); + + if (!Model.IsEmpty) + { + Model.Clear(); + } + + Model2 = Store.GetModel(new Uri("http://example.org/TestModel2")); + + if (!Model.IsEmpty) + { + Model.Clear(); + } + } + + [TearDown] + public void TearDown() + { + Model.Clear(); + Model2.Clear(); + Store.Dispose(); + } + + [Test] + public void ContainsResourceTest() + { + Uri uri = new Uri("http://example.com/testResource"); + + IModelGroup group = Store.CreateModelGroup(Model.Uri, Model2.Uri); + + Assert.IsFalse(group.ContainsResource(uri)); + + IResource resource = Model.CreateResource(uri); + resource.AddProperty(rdf.type, nco.Contact); + resource.Commit(); + + Assert.IsTrue(group.ContainsResource(uri)); + + Model.DeleteResource(resource); + + Assert.IsFalse(group.ContainsResource(uri)); + + resource = Model2.CreateResource(uri); + resource.AddProperty(rdf.type, nco.Contact); + resource.Commit(); + + Assert.IsTrue(group.ContainsResource(uri)); + } + + [Test] + public void DeleteResouceTest2() + { + var uri = new Uri("ex:Resource2"); + + IResource resource = Model.CreateResource(uri); + resource.AddProperty(rdf.type, nco.Contact); + resource.Commit(); + + Assert.IsTrue(Model.ContainsResource(uri)); + + Model.DeleteResource(resource); + + Assert.IsFalse(Model.ContainsResource(uri)); + } + + [Test] + public void GetResourceTest() + { + Uri resourceUri = new Uri("http://example.com/testResource"); + + IModelGroup g = Store.CreateModelGroup(Model.Uri, Model2.Uri); + + Assert.Throws(new TestDelegate( () => g.GetResource(resourceUri))); + + IResource resource = Model.CreateResource(resourceUri); + resource.AddProperty(rdf.type, nco.Contact); + resource.Commit(); + + IResource res = g.GetResource(resourceUri); + Assert.IsNotNull(res); + Assert.IsTrue(res.IsReadOnly); + Assert.AreEqual(resourceUri, res.Uri); + Assert.Contains(nco.Contact, res.ListValues(rdf.type).ToList()); + + + resource = Model2.CreateResource(resourceUri); + resource.AddProperty(rdf.type, nco.Contact); + resource.Commit(); + + res = g.GetResource(resourceUri); + Assert.IsNotNull(res); + Assert.AreEqual(1, res.ListValues(rdf.type).Count()); + Assert.IsTrue(res.IsReadOnly); + Assert.AreEqual(resourceUri, res.Uri); + Assert.Contains(nco.Contact, res.ListValues(rdf.type).ToList()); + + } + + [Test] + public void LazyLoadResourceTest() + { + IModel model = Model; + IModelGroup modelGroup = Store.CreateModelGroup(Model.Uri, Model2.Uri); + model.Clear(); + + Uri testRes1 = new Uri("semio:test:testInstance"); + Uri testRes2 = new Uri("semio:test:testInstance2"); + MappingTestClass t1 = model.CreateResource(testRes1); + MappingTestClass2 t2 = model.CreateResource(new Uri("semio:test:testInstance2")); + + t1.uniqueResourceTest = t2; + // TODO: Debug messsage, because t2 was not commited + t1.Commit(); + + MappingTestClass p1 = modelGroup.GetResource(testRes1); + //Assert.AreEqual(null, p1.uniqueResourceTest); + + var v = p1.ListValues(TestOntology.uniqueResourceTest); + Assert.AreEqual(t2.Uri.OriginalString, (v.First() as IResource).Uri.OriginalString); + + model.DeleteResource(t1); + + model.DeleteResource(t2); + + t1 = model.CreateResource(testRes1); + + t2 = model.CreateResource(new Uri("semio:test:testInstance2")); + t2.Commit(); + + t1.uniqueResourceTest = t2; + t1.Commit(); + + var tt1 = modelGroup.GetResource(testRes1); + Assert.AreEqual(t2, tt1.uniqueResourceTest); + + IResource tr1 = modelGroup.GetResource(testRes1); + Assert.AreEqual(typeof(MappingTestClass), tr1.GetType()); + } + } +} diff --git a/tests/Trinity.Tests.Fuseki/ModelTest.cs b/tests/Trinity.Tests.Fuseki/ModelTest.cs new file mode 100644 index 00000000..e8b9308c --- /dev/null +++ b/tests/Trinity.Tests.Fuseki/ModelTest.cs @@ -0,0 +1,794 @@ +// LICENSE: +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +// AUTHORS: +// +// Moritz Eberl +// Sebastian Faubel +// +// Copyright (c) Semiodesk GmbH 2015-2019 + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using NUnit.Framework; +using Semiodesk.Trinity.Ontologies; +using System.IO; +using System.Globalization; + +namespace Semiodesk.Trinity.Test.Fuseki +{ + [TestFixture] + public class ModelTest : SetupClass + { + private IStore Store; + + private IModel Model; + private IModel Model2; + + public ModelTest() + { + } + + [SetUp] + public void SetUp() + { + string connectionString = SetupClass.ConnectionString; + + Store = StoreFactory.CreateStore(connectionString); + Store.InitializeFromConfiguration(); + + Model = Store.GetModel(new Uri("http://example.org/TestModel")); + + if (!Model.IsEmpty) + { + Model.Clear(); + } + + Model2 = Store.GetModel(new Uri("semiodesk:Trinity:Test")); + + if (!Model2.IsEmpty) + { + Model2.Clear(); + } + + IResource model_resource = Model.CreateResource(new Uri("http://example.org/MyResource")); + + Property property = new Property(new Uri("http://example.org/MyProperty")); + model_resource.AddProperty(property, "in the jungle"); + model_resource.AddProperty(property, 123); + model_resource.AddProperty(property, DateTime.Now); + model_resource.Commit(); + + IResource model_resource2 = Model.CreateResource(new Uri("ex:Resource")); + model_resource2.AddProperty(property, "in the jungle"); + model_resource2.AddProperty(property, 123); + model_resource2.AddProperty(property, DateTime.Now); + model_resource2.Commit(); + + + IResource model2_resource = Model2.CreateResource(new Uri("http://example.org/MyResource")); + model2_resource.AddProperty(property, "in the jungle"); + model2_resource.AddProperty(property, 123); + model2_resource.AddProperty(property, DateTime.Now); + model2_resource.Commit(); + + IResource model2_resource2 = Model2.CreateResource(new Uri("ex:Resource")); + model2_resource2.AddProperty(property, "in the jungle"); + model2_resource2.AddProperty(property, 123); + model2_resource2.AddProperty(property, DateTime.Now); + model2_resource2.Commit(); + } + + [TearDown] + public void TearDown() + { + Model.Clear(); + Model2.Clear(); + Store.Dispose(); + } + + public class Contact : Resource + { + // Type Mapping + public override IEnumerable GetTypes() + { + return new List { nco.Contact }; + } + + protected PropertyMapping FullnameProperty = + new PropertyMapping("Fullname", nco.fullname); + + public string Fullname + { + get { return GetValue(FullnameProperty); } + set { SetValue(FullnameProperty, value); } + } + + protected PropertyMapping BirthdayProperty = + new PropertyMapping("Birthday", nco.birthDate); + public DateTime Birthday + { + get { return GetValue(BirthdayProperty); } + set { SetValue(BirthdayProperty, value); } + } + + public Contact(Uri uri) : base(uri) { } + } + + [Test] + public void ModelNameTest() + { + Uri modelUri = new Uri("http://doesNotExist.example.com"); + Uri modelUri2 = new Uri("http://doesNotExist.example.com/"); + + IModel m1 = Store.GetModel(modelUri); + m1.Clear(); + Assert.IsTrue(m1.IsEmpty); + + IModel m2 = Store.GetModel(modelUri2); + + Assert.IsTrue(m2.IsEmpty); + + PersonContact c = m1.CreateResource(new Uri("http://www.example.com/testResource")); + c.NameFamily = "Doe"; + c.Commit(); + + Assert.IsFalse(m1.IsEmpty); + Assert.IsTrue(m2.IsEmpty); + + m1.Clear(); + + Assert.IsTrue(m1.IsEmpty); + Assert.IsTrue(m2.IsEmpty); + + } + + [Test] + public void ContainsResourceTest() + { + Assert.IsTrue(Model.ContainsResource(new Uri("http://example.org/MyResource"))); + Assert.IsTrue(Model.ContainsResource(new Uri("ex:Resource"))); + Assert.IsTrue(Model2.ContainsResource(new Uri("http://example.org/MyResource"))); + Assert.IsTrue(Model2.ContainsResource(new Uri("ex:Resource"))); + } + + [Test] + public void CreateResourceTest() + { + Assert.IsTrue(Model.ContainsResource(new Uri("http://example.org/MyResource"))); + } + + [Test] + public void CreateEmptyResourceTest() + { + var res = Model.CreateResource(new Uri("http://semiodesk.com/emptyResource")); + res.Commit(); + } + + [Test] + public void DeleteResourceTest() + { + Uri uri0 = new Uri("http://example.org/MyResource"); + Uri uri1 = new Uri("http://example.org/MyResource1"); + + Assert.IsTrue(Model.ContainsResource(uri0)); + + Model.DeleteResource(uri0); + + Assert.IsFalse(Model.ContainsResource(uri0)); + + Property p0 = new Property(new Uri("http://example.org/MyProperty")); + Property p1 = new Property(new Uri("http://example.org/MyProperty1")); + + IResource r0 = Model.CreateResource(uri0); + r0.AddProperty(p0, "in the jungle"); + r0.AddProperty(p0, 123); + r0.Commit(); + + IResource r1 = Model.CreateResource(uri1); + r1.AddProperty(p0, 123); + r1.AddProperty(p1, r0); + r1.Commit(); + + Assert.IsTrue(Model.ContainsResource(r0)); + Assert.IsTrue(Model.ContainsResource(r1)); + + Model.DeleteResource(r0); + + Assert.IsFalse(Model.ContainsResource(r0)); + Assert.IsTrue(Model.ContainsResource(r1)); + + // Update the resource from the model. + r1 = Model.GetResource(uri1); + + Assert.IsTrue(r1.HasProperty(p0, 123)); + Assert.IsFalse(r1.HasProperty(p1, r0)); + } + + [Test] + public void DeleteResourcesTest() + { + Uri uri0 = new Uri("http://example.org/MyResource"); + Uri uri1 = new Uri("http://example.org/MyResource1"); + Property p0 = new Property(new Uri("http://example.org/MyProperty")); + Property p1 = new Property(new Uri("http://example.org/MyProperty1")); + + + IResource r1 = Model.CreateResource(uri1); + r1.AddProperty(p0, 123); + r1.AddProperty(p1, new Resource(uri0)); + r1.Commit(); + + Assert.IsTrue(Model.ContainsResource(uri0)); + Assert.IsTrue(Model.ContainsResource(uri1)); + + r1 = Model.GetResource(uri1); + var r0 = Model.GetResource(uri0); + + Model.DeleteResources(null, r0, r1); + + Assert.IsFalse(Model.ContainsResource(uri0)); + Assert.IsFalse(Model.ContainsResource(uri1)); + } + + + [Test] + public void DeleteResourcesByUrisTest() + { + Uri uri0 = new Uri("http://example.org/MyResource"); + Uri uri1 = new Uri("http://example.org/MyResource1"); + Property p0 = new Property(new Uri("http://example.org/MyProperty")); + Property p1 = new Property(new Uri("http://example.org/MyProperty1")); + + + IResource r1 = Model.CreateResource(uri1); + r1.AddProperty(p0, 123); + r1.AddProperty(p1, new Resource(uri0)); + r1.Commit(); + + Assert.IsTrue(Model.ContainsResource(uri0)); + Assert.IsTrue(Model.ContainsResource(uri1)); + + Model.DeleteResources(new Uri[] { uri0, uri1 }); + + Assert.IsFalse(Model.ContainsResource(uri0)); + Assert.IsFalse(Model.ContainsResource(uri1)); + } + + [Test] + public void GetResourceWithBlankIdTest() + { + Model.Clear(); + + Property p = new Property(new Uri("http://example.org/MyProperty")); + + IResource x = Model.CreateResource(new BlankId()); + x.AddProperty(p, 123); + x.Commit(); + + Assert.Throws(() => Model.GetResource(x.Uri)); + } + + [Test] + public void GetResourceWithBlankIdPropertyTest() + { + Model.Clear(); + + var label = new Property(new UriRef("ex:label")); + var related = new Property(new UriRef("ex:related")); + + var r0 = Model.CreateResource(new UriRef("_:0", true)); + r0.AddProperty(label, "0"); + r0.Commit(); + + var r1 = Model.CreateResource(new UriRef("_:1", true)); + r0.AddProperty(label, "1"); + r1.AddProperty(related, r0); + r1.Commit(); + + Assert.Throws(() => Model.ContainsResource(r1.Uri)); + Assert.Throws(() => Model.GetResource(r1.Uri)); + Assert.Throws(() => Model.GetResource(r1)); + + var resources = Model.GetResources().ToArray(); + + Assert.AreEqual(2, resources.Length); + + foreach (var r in resources) + { + Assert.IsTrue(r.Uri.IsBlankId); + + foreach(var x in r.ListValues(related).OfType()) + { + Assert.IsTrue(x.Uri.IsBlankId); + } + } + } + + + [Test] + public void GetResourceWithDuplicateBlankIdPropertyTest() + { + Model.Clear(); + + var label = new Property(new UriRef("ex:label")); + var related = new Property(new UriRef("ex:related")); + + var r0 = Model.CreateResource(new UriRef("_:0", true)); + r0.AddProperty(label, "0"); + r0.Commit(); + + var r1 = Model.CreateResource(new UriRef("_:0", true)); + r0.AddProperty(label, "1"); + r1.AddProperty(related, r0); + r1.Commit(); + + Assert.Throws(() => Model.ContainsResource(r1.Uri)); + Assert.Throws(() => Model.GetResource(r1.Uri)); + Assert.Throws(() => Model.GetResource(r1)); + + var resources = Model.GetResources().ToArray(); + + Assert.AreEqual(2, resources.Length); + + foreach (var r in resources) + { + Assert.IsTrue(r.Uri.IsBlankId); + + foreach (var x in r.ListValues(related).OfType()) + { + Assert.IsTrue(x.Uri.IsBlankId); + } + } + } + + [Test] + public void GetResourceTest() + { + IResource hans = Model.GetResource(new Uri("http://example.org/MyResource")); + Assert.NotNull(hans); + Assert.NotNull(hans.Model); + + hans = Model.GetResource(new Uri("http://example.org/MyResource")); + Assert.NotNull(hans); + Assert.NotNull(hans.Model); + + hans = Model.GetResource(new Uri("http://example.org/MyResource"), typeof(Resource)) as Resource; + Assert.NotNull(hans); + Assert.NotNull(hans.Model); + + try + { + Model.GetResource(new Uri("http://example.org/None")); + + Assert.Fail(); + } + catch(ArgumentException) + { + } + } + + [Test] + public void GetResourcesTest() + { + SparqlQuery query = new SparqlQuery("DESCRIBE "); + + List resources = new List(); + resources.AddRange(Model.GetResources(query)); + + Assert.Greater(resources.Count, 0); + + foreach (IResource res in resources) + { + Assert.NotNull(res.Model); + } + } + + [Test] + public void UpdateResourceTest() + { + Property property = new Property(new Uri("http://example.org/MyProperty")); + + Uri resourceUri = new Uri("http://example.org/MyResource"); + + IResource resource = Model.GetResource(resourceUri); + resource.RemoveProperty(property, 123); + resource.Commit(); + + IResource actual = Model.GetResource(resourceUri); + + Assert.AreEqual(resource, actual); + + actual = Model.GetResource(resourceUri); + + Assert.AreEqual(resource, actual); + + // Try to update resource with different properties then persisted + Resource r2 = new Resource(resourceUri); + r2.AddProperty(property, "in the jengle"); + + r2.Model = Model; + r2.Commit(); + actual = Model.GetResource(resourceUri); + Assert.AreEqual(r2, actual); + } + + [Test] + public void DateTimeResourceTest() + { + Uri resUri = new Uri("http://example.org/DateTimeTest"); + IResource res = Model.CreateResource(resUri); + + Property property = new Property(new Uri("http://example.org/MyProperty")); + + DateTime t = new DateTime(); + Assert.IsTrue(DateTime.TryParse("2013-01-21T16:27:23.000Z", out t)); + + res.AddProperty(property, t); + res.Commit(); + + IResource actual = Model.GetResource(resUri); + object o = actual.GetValue(property); + Assert.AreEqual(typeof(DateTime), o.GetType()); + DateTime actualDateTime = (DateTime)actual.GetValue(property); + + Assert.AreEqual(t.ToUniversalTime(), actualDateTime.ToUniversalTime()); + } + + [Test] + public void TimeSpanResourceTest() + { + Uri resUri = new Uri("http://example.org/DateTimeTest"); + IResource res = Model.CreateResource(resUri); + + Property property = new Property(new Uri("http://example.org/MyProperty")); + + TimeSpan t = TimeSpan.FromMinutes(5); + + res.AddProperty(property, t); + res.Commit(); + + IResource actual = Model.GetResource(resUri); + object o = actual.GetValue(property); + Assert.AreEqual(typeof(TimeSpan), o.GetType()); + TimeSpan actualDateTime = (TimeSpan)actual.GetValue(property); + + Assert.AreEqual(t.TotalMinutes, actualDateTime.TotalMinutes); + } + + [Test] + public void LiteralWithHyphenTest() + { + Model.Clear(); + + Property property = new Property(new Uri("http://example.org/MyProperty")); + + IResource model2_resource2 = Model.CreateResource(new Uri("ex:Resource")); + model2_resource2.AddProperty(property, "\"in the jungle\""); + model2_resource2.Commit(); + + IResource r = Model.GetResource(new Uri("ex:Resource")); + object o = r.GetValue(property); + Assert.AreEqual(typeof(string), o.GetType()); + Assert.AreEqual("\"in the jungle\"", o); + } + + [Test] + public void LiteralWithLangTagTest() + { + Model.Clear(); + + Property property = new Property(new Uri("http://example.org/MyProperty")); + + IResource model2_resource2 = Model.CreateResource(new Uri("ex:Resource")); + model2_resource2.AddProperty(property, "in the jungle", "EN"); + model2_resource2.Commit(); + + IResource r = Model.GetResource(new Uri("ex:Resource")); + object o = r.GetValue(property); + + Assert.AreEqual(typeof(Tuple), o.GetType()); + + var val = o as Tuple; + + Assert.AreEqual("in the jungle", val.Item1); + } + + [Test] + public void LiteralWithNewLineTest() + { + Model.Clear(); + + Property p0 = new Property(new Uri("http://example.org/MyProperty")); + + IResource r0 = Model.CreateResource(new Uri("ex:Resource")); + r0.AddProperty(p0, "in the\n jungle"); + r0.Commit(); + + r0 = Model.GetResource(new Uri("ex:Resource")); + + object o = r0.GetValue(p0); + + Assert.AreEqual(typeof(string), o.GetType()); + Assert.AreEqual("in the\n jungle", o); + } + + [Test] + public void AddResourceTest() + { + Uri uriResource = new Uri("http://example.org/AddResourceTest"); + IResource resource = new Resource (uriResource); + + Property property = new Property(new Uri("http://example.org/MyProperty")); + resource.AddProperty(property, "in the jungle"); + resource.AddProperty(property, 123); + resource.AddProperty(property, DateTime.Now); + + Model.AddResource(resource); + + IResource actual = Model.GetResource(uriResource); + + Assert.AreEqual(uriResource, uriResource); + Assert.AreEqual(resource.ListValues(property).Count(), actual.ListValues(property).Count()); + + + uriResource = new Uri("http://example.org/AddResourceTest2"); + Contact contact = new Contact(uriResource); + contact.Fullname = "Peter"; + + Model.AddResource(contact); + + Contact actualContact = Model.GetResource(uriResource); + + Assert.AreEqual(uriResource, uriResource); + Assert.AreEqual(contact.Fullname, actualContact.Fullname); + } + + [Test] + public void GetTypedResourcesTest() + { + Uri uriResource = new Uri("http://example.org/Peter"); + Contact contact = Model.CreateResource(uriResource); + contact.Fullname = "Peter"; + contact.Commit(); + + uriResource = new Uri("http://example.org/Hans"); + Contact contact2 = Model.CreateResource(uriResource); + contact2.Fullname = "Hans"; + contact2.Commit(); + + var r = Model.GetResources(); + + Assert.AreEqual(2, r.Count()); + Assert.IsTrue(r.Contains(contact)); + Assert.IsTrue(r.Contains(contact2)); + + Model.Clear(); + + PersonContact personContact = Model.CreateResource(uriResource); + personContact.Fullname = "Peter"; + personContact.Commit(); + + r = Model.GetResources(); + Assert.AreEqual(0, r.Count()); + + r = Model.GetResources(true); + Assert.AreEqual(1, r.Count()); + + var x = Model.GetResource(uriResource); + + Assert.AreEqual(typeof(PersonContact), x.GetType()); + } + + [Test] + public void WriteTest() + { + Model.Clear(); + + Property property = new Property(new Uri("http://example.org/MyProperty")); + + IResource model2_resource2 = Model.CreateResource(new Uri("ex:Resource")); + model2_resource2.AddProperty(property, "in the\n jungle"); + model2_resource2.Commit(); + + MemoryStream wr = new MemoryStream(); + Model.Write(wr, RdfSerializationFormat.RdfXml); + var myString = Encoding.UTF8.GetString(wr.ToArray()); + } + + [Test] + public void WriteWithBaseUriTest() + { + Model.Clear(); + + IResource r = Model.CreateResource(new Uri("http://example.org/test")); + r.AddProperty(new Property(new Uri("http://example.org/name")), "test"); + r.Commit(); + + using (MemoryStream stream = new MemoryStream()) + { + Model.Write(stream, RdfSerializationFormat.Turtle, null, new Uri("http://example.org/"), true); + + stream.Seek(0, SeekOrigin.Begin); + + var result = Encoding.UTF8.GetString(stream.ToArray()); + + Assert.IsFalse(string.IsNullOrEmpty(result)); + Assert.IsTrue(result.StartsWith("@base ")); + } + } + + [Test] + public void ReadTest() + { + Model.Clear(); + + FileInfo fi = new FileInfo("Models\\test-ntriples.nt"); + UriRef fileUri = fi.ToUriRef(); + + Assert.IsTrue(Model.IsEmpty); + Assert.IsTrue(Model.Read(fileUri, RdfSerializationFormat.NTriples, false)); + Assert.IsFalse(Model.IsEmpty); + + Model.Clear(); + + Assert.IsTrue(Model.IsEmpty); + Assert.IsTrue(Model.Read(new Uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#"), RdfSerializationFormat.RdfXml, false)); + Assert.IsFalse(Model.IsEmpty); + + Model.Clear(); + + fi = new FileInfo("Models\\test-tmo.trig"); + fileUri = fi.ToUriRef(); + + Assert.IsTrue(Model.IsEmpty); + Assert.Throws(typeof(ArgumentException), () => { Model.Read(fileUri, RdfSerializationFormat.Trig, false); }); + + } + + [Test] + public void ReadFromStringTest() + { + Model.Clear(); + + string turtle = @"@base . +@prefix rdf: . +@prefix rdfs: . +@prefix foaf: . +@prefix rel: . + +<#green-goblin> + rel:enemyOf <#spiderman> ; + a foaf:Person ; # in the context of the Marvel universe + foaf:name ""Green Goblin"" . +<#spiderman> + rel:enemyOf <#green-goblin> ; + a foaf:Person ; + foaf:name ""Spiderman"", ""Человек-паук""@ru ."; + + using (Stream s = GenerateStreamFromString(turtle)) + { + Assert.IsTrue(Model.Read(s, RdfSerializationFormat.Turtle, false)); + } + + IResource r = Model.GetResource(new Uri("http://example.org/#green-goblin")); + string name = r.GetValue(new Property(new Uri("http://xmlns.com/foaf/0.1/name"))) as string; + Assert.AreEqual("Green Goblin", name); + + string turtle2 = @"@base . +@prefix xsd: . +@prefix foaf: . + + +<#green-goblin> foaf:age ""27""^^xsd:int ."; + + using (Stream s = GenerateStreamFromString(turtle2)) + { + Assert.IsTrue(Model.Read(s, RdfSerializationFormat.Turtle, true)); + } + + r = Model.GetResource(new Uri("http://example.org/#green-goblin")); + int age = (int)r.GetValue(new Property(new Uri("http://xmlns.com/foaf/0.1/age"))); + name = r.GetValue(new Property(new Uri("http://xmlns.com/foaf/0.1/name"))) as string; + Assert.AreEqual(27, age); + + turtle = @"@base . +@prefix rdf: . +@prefix rdfs: . +@prefix foaf: . +@prefix rel: . + +<#green-goblin> + rel:enemyOf <#spiderman> ; + a foaf:Person ; # in the context of the Marvel universe + foaf:name ""Green Gobo"" . +<#spiderman> + rel:enemyOf <#green-goblin> ; + a foaf:Person ; + foaf:name ""Spiderman"", ""Человек-паук""@ru ."; + + using (Stream s = GenerateStreamFromString(turtle)) + { + Assert.IsTrue(Model.Read(s, RdfSerializationFormat.Turtle, false)); + } + + r = Model.GetResource(new Uri("http://example.org/#green-goblin")); + name = r.GetValue(new Property(new Uri("http://xmlns.com/foaf/0.1/name"))) as string; + Assert.AreEqual("Green Gobo", name); + } + + [Test] + public void WriteToStringTest() + { + Model.Clear(); + + + IResource r = Model.CreateResource(new Uri("http://example.org/test")); + r.AddProperty(new Property(new Uri("http://xmlns.com/foaf/0.1/name")), "test"); + r.Commit(); + MemoryStream stream = new MemoryStream(); + + Model.Write(stream, RdfSerializationFormat.Turtle, null, null, true); + + stream.Seek(0, SeekOrigin.Begin); + var res = Encoding.UTF8.GetString(stream.ToArray()); + + Assert.IsFalse(string.IsNullOrEmpty(res)); + + } + + + [Test] + public void TestAddMultipleResources() + { + Assert.Inconclusive("This test should work, it just takes too long."); + Model.Clear(); + for (int j = 1; j < 7; j++) + { + for (int i = 1; i < 1000; i++) + { + using (PersonContact pers = Model.CreateResource()) + { + pers.Fullname = string.Format("Name {0}", i * j); + pers.Commit(); + } + } + + + } + } + + public Stream GenerateStreamFromString(string s) + { + MemoryStream stream = new MemoryStream(); + StreamWriter writer = new StreamWriter(stream); + writer.Write(s); + writer.Flush(); + stream.Position = 0; + return stream; + } + + + } + + +} diff --git a/tests/Trinity.Tests.Fuseki/Program.cs b/tests/Trinity.Tests.Fuseki/Program.cs new file mode 100644 index 00000000..b605d173 --- /dev/null +++ b/tests/Trinity.Tests.Fuseki/Program.cs @@ -0,0 +1,62 @@ +// LICENSE: +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +// AUTHORS: +// +// Moritz Eberl +// Sebastian Faubel +// +// Copyright (c) Semiodesk GmbH 2015-2019 + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; + +namespace Semiodesk.Trinity.Test +{ + class TestRunner + { + [STAThread] + static void Main(string[] args) + { + string[] nunitArg = new string[args.Count() + 1]; + + int i = 0; + foreach (string arg in args) + { + nunitArg[i] = arg; + i++; + } + + nunitArg[i] = Assembly.GetExecutingAssembly().Location; + + if (i == 0) + { + // NUnit.AppEntry.Main(nunitArg); + } + else + { + // NUnit.ConsoleRunner.Runner.Main(nunitArg); + } + } + } +} diff --git a/tests/Trinity.Tests.Fuseki/ResourceBindingTest.cs b/tests/Trinity.Tests.Fuseki/ResourceBindingTest.cs new file mode 100644 index 00000000..61ceeb7d --- /dev/null +++ b/tests/Trinity.Tests.Fuseki/ResourceBindingTest.cs @@ -0,0 +1,285 @@ +// LICENSE: +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +// AUTHORS: +// +// Moritz Eberl +// Sebastian Faubel +// +// Copyright (c) Semiodesk GmbH 2015-2019 + +using Semiodesk.Trinity.Ontologies; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; +using NUnit.Framework; + +namespace Semiodesk.Trinity.Test.Fuseki +{ + + [TestFixture] + public class ResourceBindingTest + { + Uri contactListUri = new Uri("semio:test:contactList"); + IStore _store; + + [SetUp] + public void SetUp() + { + _store = StoreFactory.CreateStore("provider=virtuoso;host=localhost;port=1111;uid=dba;pw=dba;rule=urn:semiodesk/test/ruleset"); + + + } + + IModel GetModel() + { + + Uri testModelUri = new Uri("http://localhost:8899/model/TestModel"); + + IModel model = _store.GetModel(testModelUri); + return model; + } + + void InitialiseModel(IModel m) + { + m.Clear(); + + ContactList l = m.CreateResource(contactListUri); + + l.ContainsContact.Add(CreateContact(m, "Hans", new List{"Anton"}, "Meiser", new DateTime(1980, 11, 2), "meiser@test.de", "Deutschland", "Sackgasse 3", "85221", "Dachau")); + l.ContainsContact.Add(CreateContact(m, "Peter", new List{"Judith", "Ludwig"}, "Meiser", new DateTime(1981, 12, 7), "p.meiser@t-online.de", "Deutschland", "Blubweg 6", "12345", "München")); + l.ContainsContact.Add(CreateContact(m, "Franz", new List { "Hans", "Wurst" }, "Hubert", new DateTime(1976, 5, 11), "fhubert@t-online.de", "Deutschland", "Siemensstraße 183", "09876", "Berlin")); + l.ContainsContact.Add(CreateContact(m, "Isabell", new List { "Merlin"}, "Peters", new DateTime(1977, 1, 27), "isab.peters@aol.de", "Deutschland", "Walnussweg 4", "45637", "Bonn")); + l.ContainsContact.Add(CreateContact(m, "Max", new List (), "Benek", new DateTime(1989, 3, 22), "Max.Benek@aol.de", "Deutschland", "Traunweg 6", "48887", "Schweinfurt")); + l.ContainsContact.Add(CreateContact(m, "Karsten", new List { "Peter" }, "Oborn", new DateTime(1958, 7, 19), "Superchamp@gmx.de", "Deutschland", "Bei der Wurstfabrik 6", "37439", "Darmstadt")); + l.ContainsContact.Add(CreateContact(m, "Sabrina", new List { "Hans" }, "Neubert", new DateTime(1960, 8, 15), "Megabirne@gmx.net", "Deutschland", "Hanstraße 1", "55639", "Hanover")); + l.ContainsContact.Add(CreateContact(m, "Rainer", new List { "Maria" }, "Bader", new DateTime(1970, 4, 26), "Baderainer@web.de", "Deutschland", "Lalaweg 5", "86152", "Augsburg")); + l.ContainsContact.Add(CreateContact(m, "Maria", new List { "Franz" }, "Roßmann", new DateTime(1968, 10, 6), "Rossmann@web.de", "Deutschland", "Münchner Straße 9", "85123", "Odelzhausen")); + l.ContainsContact.Add(CreateContact(m, "Helga", new List { "Isabell" }, "Rößler", new DateTime(1988, 2, 1), "Roessler@gmx.de", "Deutschland", "Weiterweg 15", "12345", "München")); + l.Commit(); + } + + void InitialiseRandomModel(IModel m, int count) + { + m.Clear(); + + ContactList l = m.CreateResource(contactListUri); + + for (int i = 0; i < count; i++) + { + l.ContainsContact.Add(GenerateContact(m)); + } + + l.Commit(); + } + + public class MarkovNameGenerator + { + //constructor + public MarkovNameGenerator(IEnumerable sampleNames, int order, int minLength) + { + //fix parameter values + if (order < 1) + order = 1; + if (minLength < 1) + minLength = 1; + + _order = order; + _minLength = minLength; + + //split comma delimited lines + foreach (string line in sampleNames) + { + string[] tokens = line.Split(','); + foreach (string word in tokens) + { + string upper = word.Trim().ToUpper(); + if (upper.Length < order + 1) + continue; + _samples.Add(upper); + } + } + + //Build chains + foreach (string word in _samples) + { + for (int letter = 0; letter < word.Length - order; letter++) + { + string token = word.Substring(letter, order); + List entry = null; + if (_chains.ContainsKey(token)) + entry = _chains[token]; + else + { + entry = new List(); + _chains[token] = entry; + } + entry.Add(word[letter + order]); + } + } + } + + //Get the next random name + public string NextName + { + get + { + //get a random token somewhere in middle of sample word + string s = ""; + do + { + int n = _rnd.Next(_samples.Count); + int nameLength = _samples[n].Length; + s = _samples[n].Substring(_rnd.Next(0, _samples[n].Length - _order), _order); + while (s.Length < nameLength) + { + string token = s.Substring(s.Length - _order, _order); + char c = GetLetter(token); + if (c != '?') + s += GetLetter(token); + else + break; + } + + if (s.Contains(" ")) + { + string[] tokens = s.Split(' '); + s = ""; + for (int t = 0; t < tokens.Length; t++) + { + if (tokens[t] == "") + continue; + if (tokens[t].Length == 1) + tokens[t] = tokens[t].ToUpper(); + else + tokens[t] = tokens[t].Substring(0, 1) + tokens[t].Substring(1).ToLower(); + if (s != "") + s += " "; + s += tokens[t]; + } + } + else + s = s.Substring(0, 1) + s.Substring(1).ToLower(); + } + while (_used.Contains(s) || s.Length < _minLength); + _used.Add(s); + return s; + } + } + + //Reset the used names + public void Reset() + { + _used.Clear(); + } + + //private members + private Dictionary> _chains = new Dictionary>(); + private List _samples = new List(); + private List _used = new List(); + private Random _rnd = new Random(); + private int _order; + private int _minLength; + + //Get a random letter from the chain + private char GetLetter(string token) + { + if (!_chains.ContainsKey(token)) + return '?'; + List letters = _chains[token]; + int n = _rnd.Next(letters.Count); + return letters[n]; + } + } + + Contact GenerateContact(IModel m) + { + Random rng = new Random(); + + MarkovNameGenerator firstNameGenerator = new MarkovNameGenerator( new List{"Hans", "Peter", "Marie", "Maria", "Tina", "Tim", "Lukas", "Emma", "Tom", "Alina", "Mia", "Emma", "Siegfried", "Judith", "Karl", "Stefan", "Markus", "Martin", "Alfred", "Anton"}, 3, 5); + string firstName = firstNameGenerator.NextName; + + List additionalNames = new List(); + for (int i = rng.Next(0, 3); i > 0; i--) + { + additionalNames.Add(firstNameGenerator.NextName); + } + + MarkovNameGenerator lastNameGenerator = new MarkovNameGenerator(new List { "Maier", "Meier", "Schmied", "Schmidt", "Schulz", "Roßman", "Müller", "Klein", "Fischer", "Schwarz", "Weber", "Hofman", "Hartman", "Braun", "Koch", "Krüger", "Schröder", "Wolf", "Mayer", "Jung", "Vogel", "Lang", "Fuchs", "Huber" }, 3, 5); + string lastName = lastNameGenerator.NextName; + + DateTime start = new DateTime(1950, 1, 1); + int range = ((TimeSpan)(new DateTime(1995, 1, 1) - start)).Days; + DateTime birthDate = start.AddDays(rng.Next(range)); + + string emailAddress = string.Format("{0}.{1}@gmx.de", firstName, lastName); + + return CreateContact(m, firstName, additionalNames, lastName, birthDate, emailAddress, "Deutschland", "Teststraße 27", "123456", "Testhausen"); + } + + Contact CreateContact(IModel m, string nameGiven, List nameAdditional, string nameFamily, DateTime birthDate, string emailAddress, string country, string street, string pocode, string city) + { + Uri contactUri = new Uri("semio:"+nameGiven+":" + Guid.NewGuid().ToString()); + PersonContact c = m.CreateResource(contactUri); + StringBuilder b = new StringBuilder(); + foreach( string n in nameAdditional ) + { + b.Append(n); + b.Append(" "); + c.NameAdditional.Add(n); + } + if (b.Length > 1) + { + b.Remove(b.Length - 1, 1); + } + c.Fullname = string.Format("{0} {1} {2}", nameGiven, b, nameFamily) ; + c.NameGiven = nameGiven; + c.NameFamily = nameFamily; + c.BirthDate = birthDate; + c.EmailAddresses.Add(CreateEmailAddress(m, emailAddress)); + c.PostalAddresses.Add(CreatePostalAddress(m, country, street, pocode, city)); + + c.Commit(); + return c; + } + + EmailAddress CreateEmailAddress(IModel m, string emailAddress) + { + Uri contactUri = new Uri("semio:" + Guid.NewGuid().ToString()); + EmailAddress c = m.CreateResource(contactUri); + c.Address = emailAddress; + c.Commit(); + return c; + } + + PostalAddress CreatePostalAddress(IModel m, string country, string street, string pocode, string city) + { + Uri contactUri = new Uri("semio:" + Guid.NewGuid().ToString()); + PostalAddress c = m.CreateResource(contactUri); + c.Country = country; + c.StreetAddress = street; + c.PostalCode = pocode; + c.City = city; + c.Commit(); + return c; + } + } +} diff --git a/tests/Trinity.Tests.Fuseki/ResourceMappingTest.cs b/tests/Trinity.Tests.Fuseki/ResourceMappingTest.cs new file mode 100644 index 00000000..56e2eef9 --- /dev/null +++ b/tests/Trinity.Tests.Fuseki/ResourceMappingTest.cs @@ -0,0 +1,1464 @@ +// LICENSE: +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +// AUTHORS: +// +// Moritz Eberl +// Sebastian Faubel +// +// Copyright (c) Semiodesk GmbH 2015-2019 + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Collections.ObjectModel; +using Semiodesk.Trinity.Ontologies; +using NUnit.Framework; +using Semiodesk.Trinity.Serialization; +using Newtonsoft.Json; + +namespace Semiodesk.Trinity.Test.Fuseki +{ + + + [TestFixture] + public class ResourceMappingTest : SetupClass + { + public static bool RegisteredOntology = false; + + private IStore _store; + + [TearDown] + public void TearDown() + { + if (_store != null) + { + _store.Dispose(); + } + } + + //[Test] + // This test does not run, but it needs to. + public void AddUnmappedType() + { + IModel m = GetModel(); + m.Clear(); + + Uri t1Uri = new Uri("semio:test:testInstance1"); + Uri t2Uri = new Uri("semio:test:testInstance2"); + MappingTestClass t1 = m.CreateResource(t1Uri); + + IResource r = m.CreateResource(t2Uri); + r.AddProperty(rdf.type, TestOntology.TestClass2); + + t1.AddProperty(TestOntology.uniqueResourceTest, r); + t1.AddProperty(TestOntology.resourceTest, r); + + Assert.IsNull(t1.uniqueResourceTest); + Assert.AreEqual(0, t1.resourceTest.Count); + + m.Clear(); + } + + [Test] + public void GetTypesTest() + { + MappingTestClass2 t2 = new MappingTestClass2(new Uri("semio:t2")); + List classes = t2.GetTypes().ToList(); + Assert.AreEqual(1, classes.Count); + Assert.Contains(TestOntology.TestClass2, classes); + + MappingTestClass3 t3 = new MappingTestClass3(new Uri("semio:t3")); + classes = t3.GetTypes().ToList(); + Assert.AreEqual(1, classes.Count); + Assert.Contains(TestOntology.TestClass3, classes); + } + + [Test] + public void AddRemoveIntegerTest() + { + IModel m = GetModel(); + m.Clear(); + + Uri t1Uri = new Uri("semio:test:testInstance1"); + MappingTestClass t1 = m.CreateResource(t1Uri); + + // Add value using the mapping interface + int value = 1; + t1.uniqueIntTest = value; + + t1.Commit(); + + MappingTestClass t_actual = m.GetResource(t1Uri); + + // Test if value was stored + Assert.AreEqual(value, t_actual.uniqueIntTest); + + + // Test if property is present + IEnumerable l = t_actual.ListProperties(); + Assert.True(l.Contains(TestOntology.uniqueIntTest)); + Assert.AreEqual(2, l.Count()); + + // Test if ListValues works + Assert.AreEqual(typeof(int), t_actual.ListValues(TestOntology.uniqueIntTest).First().GetType()); + Assert.AreEqual(value, t_actual.ListValues(TestOntology.uniqueIntTest).First()); + + // Remove with RemoveProperty + t1.RemoveProperty(TestOntology.uniqueIntTest, value); + t1.Commit(); + + t_actual = m.GetResource(t1Uri); + + // Test if ListProperties works + l = t_actual.ListProperties(); + Assert.False(l.Contains(TestOntology.uniqueIntTest)); + + // Test if ListValues works + Assert.AreEqual(0, t_actual.ListValues(TestOntology.uniqueIntTest).Count()); + + m.Clear(); + } + + [Test] + public void AddRemoveIntegerListTest() + { + IModel m = GetModel(); + m.Clear(); + Uri t1Uri = new Uri("semio:test:testInstance1"); + MappingTestClass t1 = m.CreateResource(t1Uri); + // Add value using the mapping interface + int value = 2; + t1.intTest.Add(value); + + t1.Commit(); + + MappingTestClass t_actual = m.GetResource(t1Uri); + + // Test if value was stored + Assert.AreEqual(1, t_actual.intTest.Count()); + Assert.AreEqual(value, t_actual.intTest[0]); + + // Test if property is present + IEnumerable l = t_actual.ListProperties(); + Assert.True(l.Contains(TestOntology.intTest)); + Assert.AreEqual(2, l.Count()); + + // Test if ListValues works + Assert.AreEqual(typeof(int), t_actual.ListValues(TestOntology.intTest).First().GetType()); + Assert.AreEqual(value, t_actual.ListValues(TestOntology.intTest).First()); + + // Add another value + int value2 = -18583; + t1.intTest.Add(value2); + t1.Commit(); + t_actual = m.GetResource(t1Uri); + + + // Test if value was stored + Assert.AreEqual(2, t_actual.intTest.Count()); + Assert.IsTrue(t_actual.intTest.Contains(value)); + Assert.IsTrue(t_actual.intTest.Contains(value2)); + + // Test if property is present + l = t_actual.ListProperties(); + Assert.True(l.Contains(TestOntology.intTest)); + Assert.AreEqual(2, l.Count()); + + // Test if ListValues works + var res = t_actual.ListValues(TestOntology.intTest).ToList(); + Assert.AreEqual(typeof(int), res[0].GetType()); + Assert.AreEqual(typeof(int), res[1].GetType()); + Assert.IsTrue(res.Contains(value)); + Assert.IsTrue(res.Contains(value2)); + + // Remove value from mapped list + t1.intTest.Remove(value2); + t1.Commit(); + t_actual = m.GetResource(t1Uri); + + // Test if removed + Assert.AreEqual(1, t_actual.intTest.Count()); + + // Test if ListProperties works + l = t_actual.ListProperties().ToList(); + Assert.True(l.Contains(TestOntology.intTest)); + + // Test if first added property is still present + Assert.AreEqual(typeof(int), t_actual.ListValues(TestOntology.intTest).First().GetType()); + Assert.AreEqual(value, t_actual.ListValues(TestOntology.intTest).First()); + + t1.intTest.Remove(value); + t1.Commit(); + t_actual = m.GetResource(t1Uri); + + l = t_actual.ListProperties(); + Assert.False(l.Contains(TestOntology.intTest)); + + // Test if ListValues works + Assert.AreEqual(0, t_actual.ListValues(TestOntology.intTest).Count()); + + m.Clear(); + } + + /// + /// This Test fails because the datatype "unsigned int" is not stored correctly in the database. + /// To be more specific the xsd type is missing although it is given at the insert. + /// + //[Test] + public void AddRemoveUnsignedIntegerTest() + { + IModel m = GetModel(); + m.Clear(); + Uri t1Uri = new Uri("semio:test:testInstance1"); + MappingTestClass t1 = m.CreateResource(t1Uri); + + // Add value using the mapping interface + uint uValue = 1; + t1.uniqueUintTest = uValue; + + t1.Commit(); + + MappingTestClass t_actual = m.GetResource(t1Uri); + + // Test if value was stored + Assert.AreEqual(uValue, t_actual.uniqueUintTest); + + + // Test if property is present + var l = t1.ListProperties(); + Assert.True(l.Contains(TestOntology.uniqueUintTest)); + Assert.AreEqual(2, l.Count()); + + // Test if ListValues works + Assert.AreEqual(typeof(uint), t_actual.ListValues(TestOntology.uniqueUintTest).First().GetType()); + Assert.AreEqual(uValue, t_actual.ListValues(TestOntology.uniqueUintTest).First()); + + // Remove with RemoveProperty + t1.RemoveProperty(TestOntology.uniqueUintTest, uValue); + t1.Commit(); + + t_actual = m.GetResource(t1Uri); + + // Test if ListProperties works + l = (List)t_actual.ListProperties(); + Assert.False(l.Contains(TestOntology.uniqueUintTest)); + + // Test if ListValues works + Assert.AreEqual(0, t_actual.ListValues(TestOntology.uniqueUintTest).Count()); + + m.Clear(); + } + + //[Test] + public void AddRemoveUnsignedIntegerListTest() + { + IModel m = GetModel(); + m.Clear(); + Uri t1Uri = new Uri("semio:test:testInstance1"); + MappingTestClass t1 = m.CreateResource(t1Uri); + + // Add value using the mapping interface + uint uValue = 2; + t1.uintTest.Add(uValue); + + t1.Commit(); + MappingTestClass t_actual = m.GetResource(t1Uri); + + // Test if value was stored + Assert.AreEqual(1, t_actual.uintTest.Count()); + Assert.AreEqual(uValue, t_actual.uintTest[0]); + + + // Test if property is present + var l = t1.ListProperties(); + Assert.True(l.Contains(TestOntology.uintTest)); + Assert.AreEqual(2, l.Count()); + + // Test if ListValues works + Assert.AreEqual(typeof(uint), t_actual.ListValues(TestOntology.uintTest).First().GetType()); + Assert.AreEqual(uValue, t_actual.ListValues(TestOntology.uintTest).First()); + + // Remove value from mapped list + t1.uintTest.Remove(uValue); + t1.Commit(); + + t_actual = m.GetResource(t1Uri); + + // Test if removed + Assert.AreEqual(0, t_actual.uintTest.Count()); + + // Test if ListProperties works + l = (List)t_actual.ListProperties(); + Assert.False(l.Contains(TestOntology.uintTest)); + + // Test if ListValues works + Assert.AreEqual(0, t_actual.ListValues(TestOntology.uintTest).Count()); + m.Clear(); + } + + [Test] + public void AddRemoveStringTest() + { + IModel m = GetModel(); + m.Clear(); + Uri t1Uri = new Uri("semio:test:testInstance1"); + MappingTestClass t1 = m.CreateResource(t1Uri); + + + // Add value using the mapping interface + string strValue = "Hallo Welt!"; + t1.uniqueStringTest = strValue; + t1.Commit(); + + MappingTestClass t_actual = m.GetResource(t1Uri); + + // Test if value was stored + Assert.AreEqual(strValue, t_actual.uniqueStringTest); + + + // Test if property is present + var l = t_actual.ListProperties(); + Assert.True(l.Contains(TestOntology.uniqueStringTest)); + Assert.AreEqual(2, l.Count()); + + var x = t_actual.HasProperty(TestOntology.uniqueStringTest); + Assert.IsTrue(x); + + x = t_actual.HasProperty(TestOntology.uniqueStringTest, strValue); + Assert.IsTrue(x); + + // Test if ListValues works + Assert.AreEqual(typeof(string), t_actual.ListValues(TestOntology.uniqueStringTest).First().GetType()); + Assert.AreEqual(strValue, t1.ListValues(TestOntology.uniqueStringTest).First()); + + // Remove with RemoveProperty + t1.RemoveProperty(TestOntology.uniqueStringTest, strValue); + t1.Commit(); + t_actual = m.GetResource(t1Uri); + + // Test if ListProperties works + l = t_actual.ListProperties(); + Assert.False(l.Contains(TestOntology.uniqueStringTest)); + + x = t_actual.HasProperty(TestOntology.uniqueStringTest); + Assert.IsFalse(x); + + x = t_actual.HasProperty(TestOntology.uniqueStringTest, strValue); + Assert.IsFalse(x); + + // Test if ListValues works + Assert.AreEqual(0, t_actual.ListValues(TestOntology.uniqueStringTest).Count()); + + + + // Test if escaping works + t1.uniqueStringTest = "ASK { < http://steadymojo.com/sleepState> ?o. Filter( ?o != 'false'^^) }"; + t1.Commit(); + + t_actual = m.GetResource(t1Uri); + Assert.AreEqual(t_actual.uniqueStringTest, t_actual.uniqueStringTest); + + m.Clear(); + } + + [Test] + public void AddRemoveStringListTest() + { + IModel m = GetModel(); + m.Clear(); + Uri t1Uri = new Uri("semio:test:testInstance1"); + MappingTestClass t1 = m.CreateResource(t1Uri); + + // Add value using the mapping interface + string strValue = "(╯°□°)╯︵ ┻━┻"; + t1.stringTest.Add(strValue); + + t1.Commit(); + + MappingTestClass t_actual = m.GetResource(t1Uri); + + // Test if value was stored + Assert.AreEqual(1, t_actual.stringTest.Count()); + Assert.AreEqual(strValue, t_actual.stringTest[0]); + + + // Test if property is present + var l = t_actual.ListProperties(); + Assert.True(l.Contains(TestOntology.stringTest)); + Assert.AreEqual(2, l.Count()); + + var x = t_actual.HasProperty(TestOntology.stringTest); + Assert.IsTrue(x); + + x = t_actual.HasProperty(TestOntology.stringTest, strValue); + Assert.IsTrue(x); + + // Test if ListValues works + Assert.AreEqual(typeof(string), t_actual.ListValues(TestOntology.stringTest).First().GetType()); + Assert.AreEqual(strValue, t_actual.ListValues(TestOntology.stringTest).First()); + + + // Remove value from mapped list + t1.stringTest.Remove(strValue); + t1.Commit(); + + t_actual = m.GetResource(t1Uri); + + // Test if removed + Assert.AreEqual(0, t_actual.boolTest.Count()); + + // Test if ListProperties works + l = t_actual.ListProperties(); + Assert.False(l.Contains(TestOntology.stringTest)); + + x = t_actual.HasProperty(TestOntology.stringTest); + Assert.IsFalse(x); + + x = t_actual.HasProperty(TestOntology.stringTest, strValue); + Assert.IsFalse(x); + + // Test if ListValues works + Assert.AreEqual(0, t_actual.ListValues(TestOntology.stringTest).Count()); + + m.Clear(); + } + + [Test] + public void AddRemoveBoolTest() + { + IModel m = GetModel(); + m.Clear(); + Uri t1Uri = new Uri("semio:test:testInstance1"); + MappingTestClass t1 = m.CreateResource(t1Uri); + + + // Add value using the mapping interface + bool bValue = true; + t1.uniqueBoolTest = bValue; + + t1.Commit(); + + MappingTestClass t_actual = m.GetResource(t1Uri); + + // Test if value was stored + Assert.AreEqual(bValue, t_actual.uniqueBoolTest); + + + // Test if property is present + var l = t_actual.ListProperties(); + Assert.True(l.Contains(TestOntology.uniqueBoolTest)); + Assert.AreEqual(2, l.Count()); + + // Test if ListValues works + Assert.AreEqual(typeof(bool), t_actual.ListValues(TestOntology.uniqueBoolTest).First().GetType()); + Assert.AreEqual(bValue, t_actual.ListValues(TestOntology.uniqueBoolTest).First()); + + // Remove with RemoveProperty + t1.RemoveProperty(TestOntology.uniqueBoolTest, bValue); + t1.Commit(); + + t_actual = m.GetResource(t1Uri); + + // Test if ListProperties works + l = t_actual.ListProperties().ToList(); + Assert.False(l.Contains(TestOntology.uniqueBoolTest)); + + // Test if ListValues works + Assert.AreEqual(0, t_actual.ListValues(TestOntology.uniqueBoolTest).Count()); + + m.Clear(); + } + + [Test] + public void AddRemoveBoolListTest() + { + IModel model = GetModel(); + model.Clear(); + + Uri t1Uri = new Uri("semio:test:testInstance1"); + MappingTestClass t1 = model.CreateResource(t1Uri); + + // Add value using the mapping interface + bool value = true; + t1.boolTest.Add(value); + t1.Commit(); + + MappingTestClass t_actual = model.GetResource(t1Uri); + + // Test if value was stored + Assert.AreEqual(1, t_actual.boolTest.Count()); + Assert.AreEqual(value, t_actual.boolTest[0]); + + // Test if property is present + var l = t_actual.ListProperties(); + + Assert.True(l.Contains(TestOntology.boolTest)); + Assert.AreEqual(2, l.Count()); + + // Test if ListValues works + Assert.AreEqual(typeof(bool), t_actual.ListValues(TestOntology.boolTest).First().GetType()); + Assert.AreEqual(value, t_actual.ListValues(TestOntology.boolTest).First()); + + // Remove value from mapped list + t1.boolTest.Remove(value); + t1.Commit(); + + t_actual = model.GetResource(t1Uri); + + // Test if removed + Assert.AreEqual(0, t_actual.boolTest.Count()); + + // Test if ListProperties works + l = t_actual.ListProperties().ToList(); + + Assert.False(l.Contains(TestOntology.boolTest)); + + // Test if ListValues works + Assert.AreEqual(0, t_actual.ListValues(TestOntology.boolTest).Count()); + + model.Clear(); + } + + [Test] + public void AddRemoveFloatTest() + { + IModel m = GetModel(); + m.Clear(); + + Uri uri = new Uri("semio:test:testInstance1"); + + MappingTestClass testResource = m.CreateResource(uri); + + // Add value using the mapping interface + float floatValue = 1.0f; + + testResource.uniqueFloatTest = floatValue; + testResource.Commit(); + + MappingTestClass storedResource = m.GetResource(uri); + + // Test if value was stored + Assert.AreEqual(floatValue, storedResource.uniqueFloatTest); + + // Test if property is present + List properties = storedResource.ListProperties().ToList(); + + Assert.True(properties.Contains(TestOntology.uniqueFloatTest)); + Assert.AreEqual(2, properties.Count()); + + // Test if ListValues works + Assert.AreEqual(typeof(float), storedResource.ListValues(TestOntology.uniqueFloatTest).First().GetType()); + Assert.AreEqual(floatValue, storedResource.ListValues(TestOntology.uniqueFloatTest).First()); + + // Remove with RemoveProperty + testResource.RemoveProperty(TestOntology.uniqueFloatTest, floatValue); + testResource.Commit(); + + storedResource = m.GetResource(uri); + + // Test if ListProperties works + properties = storedResource.ListProperties().ToList(); + + Assert.False(properties.Contains(TestOntology.uniqueFloatTest)); + + // Test if ListValues works + Assert.AreEqual(0, storedResource.ListValues(TestOntology.uniqueFloatTest).Count()); + + m.Clear(); + } + + [Test] + public void AddRemoveDoubleTest() + { + IModel m = GetModel(); + m.Clear(); + + Uri uri = new Uri("semio:test:testInstance1"); + + MappingTestClass testResource = m.CreateResource(uri); + + // Add value using the mapping interface + double doubleValue = 1.0; + + testResource.uniqueDoubleTest = doubleValue; + testResource.Commit(); + + MappingTestClass storedResource = m.GetResource(uri); + + // Test if value was stored + Assert.AreEqual(doubleValue, storedResource.uniqueDoubleTest); + + // Test if property is present + List properties = storedResource.ListProperties().ToList(); + + Assert.True(properties.Contains(TestOntology.uniqueDoubleTest)); + Assert.AreEqual(2, properties.Count()); + + // Test if ListValues works + Assert.AreEqual(typeof(double), storedResource.ListValues(TestOntology.uniqueDoubleTest).First().GetType()); + Assert.AreEqual(doubleValue, storedResource.ListValues(TestOntology.uniqueDoubleTest).First()); + + // Remove with RemoveProperty + testResource.RemoveProperty(TestOntology.uniqueDoubleTest, doubleValue); + testResource.Commit(); + + storedResource = m.GetResource(uri); + + // Test if ListProperties works + properties = storedResource.ListProperties().ToList(); + + Assert.False(properties.Contains(TestOntology.uniqueDoubleTest)); + + // Test if ListValues works + Assert.AreEqual(0, storedResource.ListValues(TestOntology.uniqueDoubleTest).Count()); + + testResource.DoubleTest.Add(1); + testResource.DoubleTest.Add(3); + testResource.DoubleTest.Add(6); + testResource.DoubleTest.Add(17); + testResource.DoubleTest.Add(19.111); + testResource.Commit(); + + storedResource = m.GetResource(uri); + Assert.AreEqual(5, storedResource.DoubleTest.Count); + + m.Clear(); + } + + [Test] + public void AddRemoveDecimalTest() + { + IModel m = GetModel(); + m.Clear(); + + Uri uri = new Uri("semio:test:testInstance1"); + + MappingTestClass testResource = m.CreateResource(uri); + + // Add value using the mapping interface + decimal decimalValue = 1.0m; + + testResource.uniqueDecimalTest = decimalValue; + testResource.Commit(); + + MappingTestClass storedResource = m.GetResource(uri); + + // Test if value was stored + Assert.AreEqual(decimalValue, storedResource.uniqueDecimalTest); + + // Test if property is present + List properties = storedResource.ListProperties().ToList(); + + Assert.True(properties.Contains(TestOntology.uniqueDecimalTest)); + Assert.AreEqual(2, properties.Count()); + + // Test if ListValues works + Assert.AreEqual(typeof(decimal), storedResource.ListValues(TestOntology.uniqueDecimalTest).First().GetType()); + Assert.AreEqual(decimalValue, storedResource.ListValues(TestOntology.uniqueDecimalTest).First()); + + // Remove with RemoveProperty + testResource.RemoveProperty(TestOntology.uniqueDecimalTest, decimalValue); + testResource.Commit(); + + storedResource = m.GetResource(uri); + + // Test if ListProperties works + properties = storedResource.ListProperties().ToList(); + + Assert.False(properties.Contains(TestOntology.uniqueDecimalTest)); + + // Test if ListValues works + Assert.AreEqual(0, storedResource.ListValues(TestOntology.uniqueDecimalTest).Count()); + + m.Clear(); + } + + /// + /// Note: + /// Datetime precision in Virtuoso is not as high as native .net datetime precision. + /// + [Test] + public void AddRemoveDateTimeTest() + { + IModel m = GetModel(); + m.Clear(); + + Uri t1Uri = new Uri("semio:test:testInstance1"); + MappingTestClass t1 = m.CreateResource(t1Uri); + + // Add value using the mapping interface + DateTime Value = new DateTime(2012, 8, 15, 12, 3, 55, DateTimeKind.Local); + t1.uniqueDateTimeTest = Value; + t1.Commit(); + + MappingTestClass t_actual = m.GetResource(t1Uri); + + // Test if value was stored + Assert.AreEqual(Value.ToUniversalTime(), t_actual.uniqueDateTimeTest.ToUniversalTime()); + + // Test if property is present + var l = t_actual.ListProperties(); + Assert.True(l.Contains(TestOntology.uniqueDatetimeTest)); + Assert.AreEqual(2, l.Count()); + + // Test if ListValues works + Assert.AreEqual(typeof(DateTime), t_actual.ListValues(TestOntology.uniqueDatetimeTest).First().GetType()); + DateTime time = (DateTime)t_actual.ListValues(TestOntology.uniqueDatetimeTest).First(); + Assert.AreEqual(Value.ToUniversalTime(), time.ToUniversalTime()); + + // Remove with RemoveProperty + t1.RemoveProperty(TestOntology.uniqueDatetimeTest, Value); + t1.Commit(); + + t_actual = m.GetResource(t1Uri); + + // Test if ListProperties works + l = t_actual.ListProperties().ToList(); + Assert.False(l.Contains(TestOntology.uniqueDatetimeTest)); + + // Test if ListValues works + Assert.AreEqual(0, t_actual.ListValues(TestOntology.uniqueDatetimeTest).Count()); + + + DateTime t = new DateTime(); + Assert.IsTrue(DateTime.TryParse("2013-01-21T16:27:23.000Z", out t)); + + t1.uniqueDateTimeTest = t; + t1.Commit(); + + t_actual = m.GetResource(t1Uri); + Assert.AreEqual(t1.uniqueDateTimeTest, t_actual.uniqueDateTimeTest.ToLocalTime()); + + m.Clear(); + } + + [Test] + public void AddRemoveUriTest() + { + IModel model = GetModel(); + model.Clear(); + + Uri uri1 = new Uri("urn:1"); + Uri uri2 = new Uri("urn:2"); + Uri uri3 = new Uri("urn:3"); + + // 1. Create a new instance of the test class and commit it to the model. + MappingTestClass test1 = model.CreateResource(uri1); + test1.resProperty = new Resource(uri2); + test1.Commit(); + + // 2. Retrieve a new copy of the instance and validate the mapped URI property. + test1 = model.GetResource(uri1); + + Assert.NotNull(test1.resProperty); + Assert.AreEqual(test1.resProperty.Uri, uri2); + + // 3. Change the property and commit the resource. + test1.resProperty = new Resource(uri3); + test1.Commit(); + + // 4. Retrieve a new copy of the instance and validate the changed URI property. + test1 = model.GetResource(uri1); + + Assert.NotNull(test1.resProperty); + Assert.AreEqual(test1.resProperty.Uri, uri3); + } + + [Test] + public void AddRemoveUriPropTest() + { + IModel model = GetModel(); + model.Clear(); + + Uri v = new Uri("urn:test#myUri"); + + Uri t1Uri = new Uri("semio:test:testInstance1"); + MappingTestClass t1 = model.CreateResource(t1Uri); + + // Add value using the mapping interface + t1.uniqueUriTest = v; + t1.Commit(); + + MappingTestClass t_actual = model.GetResource(t1Uri); + + // Test if value was stored + Assert.IsNotNull(t_actual.uniqueUriTest); + Assert.AreEqual(v.ToString(), t_actual.uniqueUriTest.ToString()); + + // Test if property is present + var l = t_actual.ListProperties(); + Assert.True(l.Contains(TestOntology.uniqueUriTest)); + Assert.AreEqual(2, l.Count()); + + // Test if ListValues works + Assert.IsTrue( t_actual.ListValues(TestOntology.uniqueUriTest).First() is Uri); + Uri u = (Uri)t_actual.ListValues(TestOntology.uniqueUriTest).First(); + Assert.AreEqual(v.ToString(), u.ToString()); + + // Remove with RemoveProperty + t1.RemoveProperty(TestOntology.uniqueUriTest, v); + t1.Commit(); + + t_actual = model.GetResource(t1Uri); + + // Test if ListProperties works + l = t_actual.ListProperties().ToList(); + Assert.False(l.Contains(TestOntology.uniqueUriTest)); + + // Test if ListValues works + Assert.AreEqual(0, t_actual.ListValues(TestOntology.uniqueUriTest).Count()); + + t1.uriTest.Add(new Uri("urn:test#myUri1")); + t1.uriTest.Add(new Uri("urn:test#myUri2")); + t1.uriTest.Add(new Uri("urn:test3")); + t1.uriTest.Add(new Uri("urn:test/my#Uri4")); + t1.uriTest.Add(new Uri("urn:test#5")); + t1.Commit(); + + t_actual = model.GetResource(t1Uri); + Assert.AreEqual(t1.uriTest.Count, t_actual.uriTest.Count); + + + model.Clear(); + } + [Test] + public void TimeZoneTest() + { + IModel m = GetModel(); + m.Clear(); + + Uri t1Uri = new Uri("semio:test:testInstance1"); + DateTime t = new DateTime(); + Assert.IsTrue(DateTime.TryParse("2013-01-21T16:27:23.000Z", out t)); + + MappingTestClass t1 = m.CreateResource(t1Uri); + t1.uniqueDateTimeTest = t; + t1.Commit(); + + MappingTestClass t_actual = m.GetResource(t1Uri); + } + + [Test] + public void AddRemoveDateTimeListTest() + { + IModel m = GetModel(); + m.Clear(); + Uri t1Uri = new Uri("semio:test:testInstance1"); + MappingTestClass t1 = m.CreateResource(t1Uri); + + + // Add value using the mapping interface + DateTime value = new DateTime(2012, 8, 15, 12, 3, 55, DateTimeKind.Local); + t1.dateTimeTest.Add(value); + t1.Commit(); + MappingTestClass t_actual = m.GetResource(t1Uri); + + // Test if value was stored + Assert.AreEqual(1, t1.dateTimeTest.Count()); + Assert.AreEqual(value, t1.dateTimeTest[0]); + + + // Test if property is present + var l = t1.ListProperties(); + Assert.True(l.Contains(TestOntology.datetimeTest)); + Assert.AreEqual(2, l.Count()); + + // Test if ListValues works + Assert.AreEqual(typeof(DateTime), t_actual.ListValues(TestOntology.datetimeTest).First().GetType()); + DateTime time = (DateTime)t_actual.ListValues(TestOntology.datetimeTest).First(); + Assert.AreEqual(value.ToUniversalTime(), time.ToUniversalTime()); + + // Remove value from mapped list + t1.dateTimeTest.Remove(value); + t1.Commit(); + + t_actual = m.GetResource(t1Uri); + + // Test if removed + Assert.AreEqual(0, t_actual.dateTimeTest.Count()); + + // Test if ListProperties works + l = t_actual.ListProperties().ToList(); + Assert.False(l.Contains(TestOntology.datetimeTest)); + + // Test if ListValues works + Assert.AreEqual(0, t_actual.ListValues(TestOntology.datetimeTest).Count()); + } + + [Test] + public void AddRemoveResourceTest() + { + IModel m = GetModel(); + m.Clear(); + + Uri t1Uri = new Uri("semio:test:testInstance1"); + MappingTestClass t1 = m.CreateResource(t1Uri); + + Uri testClass2Uri = new Uri("semio:test:testInstance2"); + MappingTestClass2 t2 = new MappingTestClass2(testClass2Uri); + + Uri testClass3Uri = new Uri("semio:test:testInstance3"); + MappingTestClass3 t3 = m.CreateResource(testClass3Uri); + t3.Commit(); // Force loading the resource from the model with the appropriate (derived) type. + + t1.uniqueResourceTest = t2; + t1.Commit(); + + MappingTestClass t_actual = m.GetResource(t1Uri); + + Assert.AreEqual(t2, t_actual.uniqueResourceTest); + + var l = t_actual.ListProperties().ToList(); + Assert.Contains(TestOntology.uniqueResourceTest, l); + Assert.AreEqual(2, l.Count()); + + var x = t_actual.HasProperty(TestOntology.uniqueResourceTest); + Assert.IsTrue(x); + + x = t_actual.HasProperty(TestOntology.uniqueResourceTest, t2); + Assert.IsTrue(x); + + t_actual = m.GetResource(t1Uri); + var values = t_actual.ListValues().ToList(); + Assert.Contains( new Tuple(TestOntology.uniqueResourceTest, t2), values); + + + Assert.IsTrue(typeof(Resource).IsAssignableFrom(t_actual.ListValues(TestOntology.uniqueResourceTest).First().GetType())); + //Assert.AreEqual(t2, t_actual.ListValues(TestOntology.uniqeResourceTest).First()); + + t1.RemoveProperty(TestOntology.uniqueResourceTest, t2); + t1.Commit(); + t_actual = m.GetResource(t1Uri); + + + l = t_actual.ListProperties().ToList(); + Assert.False(l.Contains(TestOntology.uniqueResourceTest)); + + x = t_actual.HasProperty(TestOntology.uniqueResourceTest); + Assert.IsFalse(x); + + x = t_actual.HasProperty(TestOntology.uniqueResourceTest, t2); + Assert.IsFalse(x); + + // Test if ListValues works + Assert.AreEqual(0, t_actual.ListValues(TestOntology.uniqueResourceTest).Count()); + + // Test if derived types get properly mapped. + t1.uniqueResourceTest = t3; + t1.Commit(); + + t_actual = m.GetResource(t1Uri); + + Assert.AreEqual(t3, t_actual.uniqueResourceTest); + } + + [Test] + public void AddRemoveResourceListTest() + { + IModel m = GetModel(); + m.Clear(); + + Uri t1Uri = new Uri("semio:test:testInstance1"); + MappingTestClass t1 = m.CreateResource(t1Uri); + + // Add value using the mapping interface + MappingTestClass2 t2 = new MappingTestClass2(new Uri("semio:test:testInstance2")); + MappingTestClass3 t3 = new MappingTestClass3(new Uri("semio:test:testInstance3")); + + t1.resourceTest.Add(t2); + t1.resourceTest.Add(t3); + t1.Commit(); + + MappingTestClass t_actual = m.GetResource(t1Uri); + + Assert.AreEqual(2, t_actual.resourceTest.Count); + Assert.Contains(t2, t_actual.resourceTest); + Assert.Contains(t3, t_actual.resourceTest); + + var l = t_actual.ListProperties(); + + Assert.AreEqual(2, l.Count()); + Assert.IsTrue(l.Contains(TestOntology.resourceTest)); + + var x = t_actual.HasProperty(TestOntology.resourceTest); + Assert.IsTrue(x); + + x = t_actual.HasProperty(TestOntology.resourceTest, t2); + Assert.IsTrue(x); + + x = t_actual.HasProperty(TestOntology.resourceTest, t3); + Assert.IsTrue(x); + + var v = t_actual.ListValues(TestOntology.resourceTest); + + Assert.AreEqual(2, l.Count()); + Assert.IsTrue(v.Contains(t2)); + Assert.IsTrue(v.Contains(t3)); + + t1.resourceTest.Remove(t2); + t1.resourceTest.Remove(t3); + t1.Commit(); + + t_actual = m.GetResource(t1Uri); + + x = t_actual.HasProperty(TestOntology.resourceTest); + Assert.IsFalse(x); + + x = t_actual.HasProperty(TestOntology.resourceTest, t2); + Assert.IsFalse(x); + + Assert.AreEqual(0, t_actual.resourceTest.Count); + } + + [Test] + public void LazyLoadResourceTest() + { + + IModel model = GetModel(); + model.Clear(); + + Uri testRes1 = new Uri("semio:test:testInstance"); + Uri testRes2 = new Uri("semio:test:testInstance2"); + MappingTestClass t1 = model.CreateResource(testRes1); + MappingTestClass2 t2 = model.CreateResource(new Uri("semio:test:testInstance2")); + + t1.uniqueResourceTest = t2; + // TODO: Debug messsage, because t2 was not commited + t1.Commit(); + + MappingTestClass p1 = model.GetResource(testRes1); + //Assert.AreEqual(null, p1.uniqueResourceTest); + + var v = p1.ListValues(TestOntology.uniqueResourceTest); + Assert.AreEqual(t2.Uri.OriginalString, (v.First() as IResource).Uri.OriginalString); + + model.DeleteResource(t1); + + model.DeleteResource(t2); + + t1 = model.CreateResource(testRes1); + + t2 = model.CreateResource(new Uri("semio:test:testInstance2")); + t2.Commit(); + + t1.uniqueResourceTest = t2; + t1.Commit(); + + var tt1 = model.GetResource(testRes1); + Assert.AreEqual(t2, tt1.uniqueResourceTest); + + IResource tr1 = model.GetResource(testRes1); + Assert.AreEqual(typeof(MappingTestClass), tr1.GetType()); + + model.Clear(); + _store.RemoveModel(model); + } + + [Test] + public void MappingTypeTest() + { + IModel m = GetModel(); + m.Clear(); + Uri t1Uri = new Uri("semio:test:testInstance1"); + MappingTestClass2 t1 = m.CreateResource(t1Uri); + //Assert.AreEqual(1, t1.Classes.Count); + t1.uniqueStringTest = "testing 1"; + t1.Commit(); + + Uri t2Uri = new Uri("semio:test:testInstance2"); + MappingTestClass3 t2 = m.CreateResource(t2Uri); + t2.uniqueStringTest = "testing 2"; + t2.Commit(); + + Uri t3Uri = new Uri("semio:test:testInstance3"); + MappingTestClass4 t3 = m.CreateResource(t3Uri); + t3.uniqueStringTest = "testing 3"; + t3.Commit(); + + Resource r1 = m.GetResource(t1Uri); + Assert.AreEqual(t1, r1); + + Resource r2 = m.GetResource(t2Uri); + Assert.AreEqual(t2, r2); + + Resource r3 = m.GetResource(t3Uri); + Assert.AreEqual(t3, r3); + + r2 = m.GetResource(t2Uri); + Assert.AreEqual(t2, r2); + + } + + [Test] + public void MappingTypeCollectionTest() + { + IModel m = GetModel(); + m.Clear(); + + Uri t2Uri = new Uri("semio:test:testInstance2"); + PersonContact t2 = m.CreateResource(t2Uri); + t2.NameFamily = "Doe"; + t2.Commit(); + + var list = m.GetResources(true).ToList() ; + Assert.AreEqual(1, list); + } + + [Test] + public void MultipeTypesMappingTest() + { + IModel m = GetModel(); + m.Clear(); + + Uri t3Uri = new Uri("semio:test:testInstance3"); + MappingTestClass5 t3 = m.CreateResource(t3Uri); + t3.uniqueStringTest = "testing 3"; + t3.AddProperty(rdf.type, nco.Affiliation); + t3.Commit(); + + Resource r3 = m.GetResource(t3Uri); + Type tr3 = r3.GetType(); + Type tt3 = typeof(MappingTestClass5); + Assert.AreEqual(typeof(MappingTestClass5), r3.GetType()); + + m.Clear(); + t3 = m.CreateResource(t3Uri); + t3.uniqueStringTest = "testing 3"; + t3.AddProperty(rdf.type, nco.Contact); + t3.Commit(); + + r3 = m.GetResource(t3Uri); + Assert.AreEqual(typeof(MappingTestClass5), r3.GetType()); + + r3 = m.GetResource(t3Uri); + Assert.AreEqual(typeof(Contact), r3.GetType()); + } + + [Test] + public void MappingTypeWithInferencingTest() + { + IModel model = GetModel(); + + // Load the rulesets for inferencing. + _store.InitializeFromConfiguration(); + + model.Clear(); + + PersonContact r = model.CreateResource(new Uri("ex:t3")); + r.NameGiven = "Hans"; + r.Commit(); + + SparqlQuery query = new SparqlQuery("SELECT ?s ?p ?o WHERE { ?s ?p ?o . ?s a @type .}"); + query.Bind("@type", nco.Contact); + + Assert.AreEqual(1, model.ExecuteQuery(query, true).GetResources().Count()); + } + + IModel GetModel() + { + _store = StoreFactory.CreateStore(string.Format("{0};rule=urn:semiodesk/test/ruleset", SetupClass.ConnectionString)); + _store.InitializeFromConfiguration(); + return _store.GetModel(new Uri("http://example.org/TestModel")); + } + + [Test] + public void RollbackTest() + { + IModel model = GetModel(); + model.Clear(); + + Uri t1Uri = new Uri("semio:test:testInstance1"); + MappingTestClass t1 = model.CreateResource(t1Uri); + + // Add value using the mapping interface + string strValue = "Hallo Welt!"; + t1.uniqueStringTest = strValue; + t1.Commit(); + + t1.uniqueStringTest = "HelloWorld!"; + + t1.Rollback(); + + Assert.AreEqual(strValue, t1.uniqueStringTest); + + MappingTestClass newRef = model.GetResource(t1Uri); + newRef.stringTest.Add("Hi"); + newRef.stringTest.Add("Blub"); + newRef.Commit(); + + t1.Rollback(); + + Assert.AreEqual(2, t1.stringTest.Count); + Assert.IsTrue(t1.stringTest.Contains("Hi")); + Assert.IsTrue(t1.stringTest.Contains("Blub")); + + Uri t2Uri = new Uri("semio:test:testInstance2"); + MappingTestClass2 p = model.CreateResource(t2Uri); + p.uniqueStringTest = "blub"; + p.Commit(); + + newRef = model.GetResource(t1Uri); + newRef.resourceTest.Add(p); + newRef.Commit(); + + t1.Rollback(); + + Assert.IsTrue(t1.resourceTest.Count == 1); + Assert.IsTrue(t1.resourceTest.Contains(p)); + } + + [Test] + public void RollbackMappedResourcesTest() + { + IModel m = GetModel(); + m.Clear(); + Uri t1Uri = new Uri("semio:test:testInstance1"); + SingleResourceMappingTestClass t1 = m.CreateResource(t1Uri); + t1.Commit(); + + Uri t2Uri = new Uri("semio:test:testInstance2"); + SingleMappingTestClass p = m.CreateResource(t2Uri); + p.stringTest.Add("blub"); + p.Commit(); + + var newRef = m.GetResource(t1Uri); + newRef.ResourceTest.Add(p); + newRef.Commit(); + + t1.Rollback(); + + Assert.IsTrue(t1.ResourceTest.Count == 1); + Assert.IsTrue(t1.ResourceTest.Contains(p)); + } + + [Test] + public void ListValuesTest() + { + IModel m = GetModel(); + m.Clear(); + Uri t1Uri = new Uri("semio:test:testInstance1"); + MappingTestClass t1 = m.CreateResource(t1Uri); + + + // Add value using the mapping interface + string strValue = "Hallo Welt!"; + t1.uniqueStringTest = strValue; + t1.Commit(); + + t1.stringTest.Add("Hi"); + t1.stringTest.Add("Blub"); + t1.Commit(); + + var x = t1.ListValues(TestOntology.stringTest).ToList(); + + MappingTestClass actual = m.GetResource(t1.Uri); + var x2 = actual.ListValues(TestOntology.stringTest).ToList().ToList(); + + Assert.AreEqual(x.Count, x2.Count); + Assert.IsTrue(x2.Contains(x[0])); + Assert.IsTrue(x2.Contains(x[1])); + } + + [Test] + public void KeepListsAfterRollbackTest() + { + IModel m = GetModel(); + m.Clear(); + Uri t1Uri = new Uri("semio:test:testInstance8"); + SingleMappingTestClass t1 = m.CreateResource(t1Uri); + t1.AddProperty(TestOntology.uniqueStringTest, "Hello"); + t1.Commit(); + t1.Rollback(); + + t1.stringTest.Add("Hi"); + t1.stringTest.Add("Blub"); + var x = t1.ListValues(TestOntology.stringTest).ToList(); + Assert.AreEqual(2, x.Count); + t1.Commit(); + + SingleMappingTestClass t2 = m.GetResource(t1Uri); + + var x2 = t2.ListValues(TestOntology.stringTest).ToList(); + + Assert.AreEqual(x.Count, x2.Count); + Assert.IsTrue(x2.Contains(x[0])); + Assert.IsTrue(x2.Contains(x[1])); + + } + + [Test] + public void TestEquality() + { + Resource c1 = new Resource(new Uri("http://www.semanticdesktop.org/ontologies/2007/04/02/ncal#cancelledStatus")); + Resource c2 = new Resource(new Uri("http://www.semanticdesktop.org/ontologies/2007/04/02/ncal#cancelledStatus")); + + Assert.IsTrue(c1.Equals(c2)); + Assert.IsFalse(c1 == c2); + } + + [Test] + public void TestStringPropertyMapping() + { + StringMappingTestClass p = new StringMappingTestClass(new Uri("http://test.example.com")); + p.uniqueStringTest = "Test string"; + + var x = p.GetValue(TestOntology.uniqueStringTest); + Assert.AreEqual(p.uniqueStringTest, x); + + p.RandomProperty = "Test string 2"; + + x = p.GetValue(new Property(new Uri("http://www.example.com/property"))); + Assert.AreEqual(p.RandomProperty, x); + } + + [Test] + public void TestLocalizedStringPropertyMapping() + { + IModel m = GetModel(); + m.Clear(); + var resUri = new Uri("http://test.example.com"); + StringMappingTestClass p = m.CreateResource(resUri); + + string germanText = "Hallo Welt"; + string englishText = "Hello World"; + p.AddProperty(TestOntology.uniqueStringTest, germanText, "DE"); + p.AddProperty(TestOntology.uniqueStringTest, englishText, "EN"); + Assert.AreEqual(null, p.uniqueStringTest); + p.Language = "DE"; + Assert.AreEqual(germanText, p.uniqueStringTest); + var x = p.ListValues(TestOntology.uniqueStringTest); + p.Language = "EN"; + Assert.AreEqual(englishText, p.uniqueStringTest); + + p.Language = null; + Assert.AreEqual(null, p.uniqueStringTest); + + } + + [Test] + public void TestLocalizedStringInvariancy() + { + IModel m = GetModel(); + m.Clear(); + Uri peterUri = new Uri("http://test.example.com/peter"); + PersonContact contact = m.CreateResource(peterUri); + contact.NameGiven = "Peter"; + contact.Language = "DE"; + Assert.AreEqual("Peter", contact.NameGiven); + } + + + [Test] + public void TestLocalizedStringListPropertyMapping() + { + IModel m = GetModel(); + m.Clear(); + var resUri = new Uri("http://test.example.com"); + StringMappingTestClass p = m.CreateResource(resUri); + + string germanText = "Hallo Welt"; + string englishText = "Hello World"; + p.AddProperty(TestOntology.stringTest, germanText+1, "DE"); + p.AddProperty(TestOntology.stringTest, germanText+2, "de"); + p.AddProperty(TestOntology.stringTest, germanText+3, "DE"); + p.AddProperty(TestOntology.stringTest, englishText+1, "EN"); + p.AddProperty(TestOntology.stringTest, englishText+2, "EN"); + p.AddProperty(TestOntology.stringTest, englishText+3, "EN"); + p.AddProperty(TestOntology.stringTest, englishText+4, "EN"); + Assert.AreEqual(0, p.stringListTest.Count); + var x = p.ListValues(TestOntology.stringTest); + Assert.AreEqual(7, x.Count()); + p.AddProperty(TestOntology.stringTest, "Hello interanational World"+1); + p.AddProperty(TestOntology.stringTest, "Hello interanational World"+2); + Assert.AreEqual(2, p.stringListTest.Count); + Assert.AreEqual(9, p.ListValues(TestOntology.stringTest).Count()); + p.Language = "DE"; + Assert.AreEqual(3, p.stringListTest.Count); + Assert.AreEqual(9, p.ListValues(TestOntology.stringTest).Count()); + p.Language = "EN"; + Assert.AreEqual(4, p.stringListTest.Count); + Assert.AreEqual(9, p.ListValues(TestOntology.stringTest).Count()); + p.RemoveProperty(TestOntology.stringTest, germanText + 1, "DE"); + Assert.AreEqual(8, p.ListValues(TestOntology.stringTest).Count()); + + p.RemoveProperty(TestOntology.stringTest, englishText + 1, "en"); + Assert.AreEqual(8, p.ListValues(TestOntology.stringTest).Count()); + + p.RemoveProperty(TestOntology.stringTest, "Hello interanational World" + 1); + + + } + + [Test] + public void TestLocalizedStringListPropertyMapping2() + { + IModel m = GetModel(); + m.Clear(); + var resUri = new Uri("http://test.example.com"); + StringMappingTestClass p = m.CreateResource(resUri); + + p.stringListTest.Add("Hello interanational World" + 1); + p.stringListTest.Add("Hello interanational World" + 2); + string germanText = "Hallo Welt"; + string englishText = "Hello World"; + p.Language = "DE"; + p.stringListTest.Add(germanText + 1); + p.stringListTest.Add(germanText + 2); + p.stringListTest.Add(germanText + 3); + Assert.AreEqual(3, p.stringListTest.Count); + Assert.AreEqual(5, p.ListValues(TestOntology.stringTest).Count()); + + p.Language = "EN"; + p.stringListTest.Add(englishText + 1); + p.stringListTest.Add(englishText + 2); + p.stringListTest.Add(englishText + 3); + p.stringListTest.Add(englishText + 4); + Assert.AreEqual(4, p.stringListTest.Count); + Assert.AreEqual(9, p.ListValues(TestOntology.stringTest).Count()); + + p.Language = null; + Assert.AreEqual(2, p.stringListTest.Count); + Assert.AreEqual(9, p.ListValues(TestOntology.stringTest).Count()); + } + + [Test] + public void TestJsonSerialization() + { + IModel model = GetModel(); + model.Clear(); + + JsonMappingTestClass expected = model.CreateResource(); + expected.stringTest.Add("Hello World!"); + expected.stringTest.Add("Hallo Welt!"); + expected.Commit(); + + string json = JsonConvert.SerializeObject(expected); + + JsonResourceSerializerSettings settings = new JsonResourceSerializerSettings(_store); + + JsonMappingTestClass actual = JsonConvert.DeserializeObject(json, settings); + + Assert.AreEqual(expected.Uri, actual.Uri); + Assert.AreEqual(expected.Model.Uri, actual.Model.Uri); + Assert.AreEqual(2, actual.stringTest.Count); + } + } +} diff --git a/tests/Trinity.Tests.Fuseki/SetupClass.cs b/tests/Trinity.Tests.Fuseki/SetupClass.cs new file mode 100644 index 00000000..6055109e --- /dev/null +++ b/tests/Trinity.Tests.Fuseki/SetupClass.cs @@ -0,0 +1,52 @@ +using System.Reflection; +using System.IO; +using NUnit.Framework; +using Semiodesk.Trinity.Store.Fuseki; + +namespace Semiodesk.Trinity.Test.Fuseki +{ + + public class SetupClass + { + #region Members + public static string ConnectionString; + + #endregion + + #region Methods + + [OneTimeSetUp] + public void OneTimeSetup() + { + Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); + + StoreFactory.LoadProvider(); + OntologyDiscovery.AddAssembly(Assembly.GetExecutingAssembly()); + MappingDiscovery.RegisterAssembly(Assembly.GetExecutingAssembly()); + OntologyDiscovery.AddAssembly(typeof(AbstractMappingClass).Assembly); + MappingDiscovery.RegisterAssembly(typeof(AbstractMappingClass).Assembly); + + FileInfo location = new FileInfo(Assembly.GetExecutingAssembly().Location); + DirectoryInfo folder = new DirectoryInfo(Path.Combine(location.DirectoryName, "nunit")); + + if (folder.Exists) + { + folder.Delete(true); + } + + folder.Create(); + + + ConnectionString = "provider=fuseki;host=http://localhost:3030;dataset=ds"; + + } + + [OneTimeTearDown] + public void OneTimeTearDown() + { + + } + + #endregion + } +} diff --git a/tests/Trinity.Tests.Fuseki/SparqlQueryTest.cs b/tests/Trinity.Tests.Fuseki/SparqlQueryTest.cs new file mode 100644 index 00000000..8bf34775 --- /dev/null +++ b/tests/Trinity.Tests.Fuseki/SparqlQueryTest.cs @@ -0,0 +1,534 @@ +// LICENSE: +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +// AUTHORS: +// +// Moritz Eberl +// Sebastian Faubel +// +// Copyright (c) Semiodesk GmbH 2015-2019 + +using NUnit.Framework; +using Semiodesk.Trinity.Ontologies; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text.RegularExpressions; + +namespace Semiodesk.Trinity.Test.Fuseki +{ + [TestFixture] + public class SparqlQueryTest : SetupClass + { + protected IStore Store; + + protected IModel Model; + + [SetUp] + public void SetUp() + { + OntologyDiscovery.AddNamespace("ex", new Uri("http://example.org/")); + OntologyDiscovery.AddNamespace("dc", new Uri("http://purl.org/dc/elements/1.1/")); + OntologyDiscovery.AddNamespace("vcard", new Uri("http://www.w3.org/2001/vcard-rdf/3.0#")); + OntologyDiscovery.AddNamespace("foaf", new Uri("http://xmlns.com/foaf/0.1/")); + OntologyDiscovery.AddNamespace("dbpedia", new Uri("http://dbpedia.org/ontology/")); + OntologyDiscovery.AddNamespace("dbpprop", new Uri("http://dbpedia.org/property/")); + OntologyDiscovery.AddNamespace("schema", new Uri("http://schema.org/")); + OntologyDiscovery.AddNamespace("nie", new Uri("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#")); + OntologyDiscovery.AddNamespace("nco", new Uri("http://www.semanticdesktop.org/ontologies/2007/03/22/nco#")); + OntologyDiscovery.AddNamespace("sfo", sfo.GetNamespace()); + OntologyDiscovery.AddNamespace(nfo.GetPrefix(), nfo.GetNamespace()); + + Store = StoreFactory.CreateStore(string.Format("{0};rule=urn:semiodesk/test/ruleset", SetupClass.ConnectionString)); + Store.InitializeFromConfiguration(); + + Model = Store.GetModel(new Uri("http://example.org/TestModel")); + Model.Clear(); + + IResource hans = Model.CreateResource(new Uri("http://example.org/Hans")); + hans.AddProperty(rdf.type, nco.PersonContact); + hans.AddProperty(nco.fullname, "Hans Wurscht"); + hans.AddProperty(nco.birthDate, DateTime.Now); + hans.AddProperty(nco.blogUrl, "http://blog.com/Hans"); + + IResource pagerNumber0 = Model.CreateResource(new Uri("http://example.org/Hans/pagerNumber#0")); + pagerNumber0.AddProperty(rdf.type, nco.PagerNumber); + pagerNumber0.AddProperty(dc.date, DateTime.Today); + pagerNumber0.AddProperty(nco.creator, hans); + pagerNumber0.Commit(); + + IResource phoneNumber0 = Model.CreateResource(new Uri("http://example.org/Hans/phoneNumber#0")); + phoneNumber0.AddProperty(rdf.type, nco.PhoneNumber); + phoneNumber0.AddProperty(dc.date, DateTime.Today.AddDays(1)); + phoneNumber0.AddProperty(nco.creator, hans); + phoneNumber0.Commit(); + + IResource phoneNumber1 = Model.CreateResource(new Uri("http://example.org/Hans/phoneNumber#1")); + phoneNumber1.AddProperty(rdf.type, nco.PhoneNumber); + phoneNumber1.AddProperty(dc.date, DateTime.Today.AddDays(2)); + phoneNumber1.AddProperty(nco.creator, hans); + phoneNumber1.Commit(); + + hans.AddProperty(nco.hasContactMedium, pagerNumber0); + hans.AddProperty(nco.hasPhoneNumber, phoneNumber0); + hans.AddProperty(nco.hasPhoneNumber, phoneNumber1); + hans.Commit(); + + IResource acme = Model.CreateResource(new Uri("http://example.org/ACME")); + acme.AddProperty(rdf.type, nco.OrganizationContact); + acme.AddProperty(nco.fullname, "ACME"); + acme.AddProperty(nco.creator, hans); + acme.Commit(); + } + + [TearDown] + public void TearDown() + { + if (Store != null) + { + Store.Dispose(); + } + } + + [Test] + public void TestAsk() + { + // Checking the model using ASK queries. + SparqlQuery query = new SparqlQuery("ASK WHERE { ?s nco:fullname 'Hans Wurscht' . }"); + ISparqlQueryResult result = Model.ExecuteQuery(query); + + Assert.AreEqual(true, result.GetAnwser()); + + query = new SparqlQuery("ASK WHERE { ?s nco:fullname 'Hans Meier' . }"); + result = Model.ExecuteQuery(query); + + Assert.AreEqual(false, result.GetAnwser()); + } + + [Test] + public void TestSelect() + { + // Retrieving bound variables using the SELECT query form. + SparqlQuery query = new SparqlQuery("SELECT ?name ?birthday WHERE { ?x nco:fullname ?name. ?x nco:birthDate ?birthday. }"); + ISparqlQueryResult result = Model.ExecuteQuery(query); + + Assert.AreEqual(1, result.GetBindings().Count()); + + // Retrieving resoures using the SELECT or DESCRIBE query form. + query = new SparqlQuery("SELECT ?s ?p ?o WHERE { ?s ?p ?o. ?s nco:fullname 'Hans Wurscht'. }"); + result = Model.ExecuteQuery(query); + + Assert.AreEqual(1, result.GetResources().Count()); + + // Test SELECT with custom defined PREFIXes + query = new SparqlQuery("PREFIX nco: SELECT ?s ?p ?o WHERE { ?s ?p ?o. ?s nco:fullname 'Hans Wurscht'. }"); + result = Model.ExecuteQuery(query); + + Assert.AreEqual(1, result.GetResources().Count()); + + // Check if the select statement only works on the given model. + query = new SparqlQuery("SELECT * WHERE { ?s ?p ?o. }"); + result = Model.ExecuteQuery(query); + + Assert.AreEqual(5, result.GetResources().Count()); + + // Check that resource creation is done correctly for Resources containing dashes. + IResource r0 = Model.CreateResource(new Uri("http://example.org/Something#0")); + r0.AddProperty(new Property(new Uri("http://example.org/fullName")), "Something"); + r0.Commit(); + + IResource r1 = Model.CreateResource(new Uri("http://example.org/Something#1")); + r1.AddProperty(new Property(new Uri("http://example.org/fullName")), "Anotherthing"); + r1.Commit(); + + query = new SparqlQuery("SELECT * WHERE { ?s ?p ?o. }"); + result = Model.ExecuteQuery(query); + + Assert.AreEqual(7, result.GetResources().Count()); + } + + [Test] + public void TestSelectProvidesStatements() + { + SparqlQuery query = new SparqlQuery("SELECT ?s ?p ?o WHERE { ?s ?p ?o . }"); + + string[] vars = query.GetGlobalScopeVariableNames(); + + Assert.IsTrue(query.ProvidesStatements()); + Assert.AreEqual("s", vars[0]); + Assert.AreEqual("p", vars[1]); + Assert.AreEqual("o", vars[2]); + + query = new SparqlQuery("SELECT * WHERE { ?s ?p ?o . }"); + + vars = query.GetGlobalScopeVariableNames(); + + Assert.IsTrue(query.ProvidesStatements()); + Assert.AreEqual("s", vars[0]); + Assert.AreEqual("p", vars[1]); + Assert.AreEqual("o", vars[2]); + + query = new SparqlQuery("SELECT ?s ?p ?o WHERE { ?s ?p ?o . ?x ?y ?z . }"); + + vars = query.GetGlobalScopeVariableNames(); + + Assert.IsTrue(query.ProvidesStatements()); + Assert.AreEqual("s", vars[0]); + Assert.AreEqual("p", vars[1]); + Assert.AreEqual("o", vars[2]); + + query = new SparqlQuery("SELECT * WHERE { ?s ?p ?o . ?x ?y ?z . }"); + + vars = query.GetGlobalScopeVariableNames(); + + Assert.IsFalse(query.ProvidesStatements()); + Assert.AreEqual(6, vars.Length); + + query = new SparqlQuery(@" + PREFIX nie: + PREFIX artpro: + + SELECT ?s ?p ?o WHERE + { + ?s ?p ?o . + ?s a artpro:Project . + ?s nie:lastModified ?lastModified . + + FILTER isIRI(?s) + } + ORDER BY DESC(?lastModified)"); + + vars = query.GetGlobalScopeVariableNames(); + + Assert.IsTrue(query.ProvidesStatements()); + Assert.AreEqual("s", vars[0]); + Assert.AreEqual("p", vars[1]); + Assert.AreEqual("o", vars[2]); + } + + [Test] + public void TestDescribe() + { + SparqlQuery query = new SparqlQuery("DESCRIBE "); + ISparqlQueryResult result = Model.ExecuteQuery(query); + + IList resources = result.GetResources().ToList(); + Assert.AreEqual(1, resources.Count); + + query = new SparqlQuery("DESCRIBE ?s WHERE { ?s nco:fullname 'Hans Wurscht'. }"); + result = Model.ExecuteQuery(query); + + resources = result.GetResources().ToList(); + Assert.AreEqual(1, resources.Count); + + foreach (Contact c in resources) + { + Assert.AreEqual(c.GetType(), typeof(PersonContact)); + } + } + + [Test] + public void TestConstruct() + { + SparqlQuery query = new SparqlQuery(@" + CONSTRUCT + { + ?x nco:fullname ?name . + ?x vcard:N _:v . + _:v vcard:givenName ?name . + } + WHERE + { + ?x nco:fullname ?name . + }"); + + List resources = Model.GetResources(query).ToList(); + + // We expect 4 resources: 2 VCARD blank nodes and the original 2 NCO contacts. + Assert.AreEqual(4, resources.Count); + Assert.AreEqual(2, resources.Count(r => r.HasProperty(nco.fullname))); + Assert.AreEqual(2, resources.Count(r => r.HasProperty(vcard.N))); + Assert.AreEqual(2, resources.Count(r => r.HasProperty(vcard.givenName))); + } + + [Test] + public void TestInferencing() + { + // Retrieving resources using the model API. + Assert.IsTrue(Model.ContainsResource(new Uri("http://example.org/Hans"))); + Assert.IsTrue(Model.ContainsResource(new Uri("http://example.org/ACME"))); + + SparqlQuery query; + ISparqlQueryResult result; + + // This fact is not explicitly stated. + query = new SparqlQuery("ASK WHERE { a nco:Role . }"); + + result = Model.ExecuteQuery(query); + Assert.IsFalse(result.GetAnwser()); + + result = Model.ExecuteQuery(query, true); + Assert.IsTrue(result.GetAnwser()); + + // This fact is not explicitly stated. + query = new SparqlQuery("SELECT ?url WHERE { ?x nco:url ?url . }"); + + result = Model.ExecuteQuery(query); + Assert.AreEqual(0, result.GetBindings().Count()); + + result = Model.ExecuteQuery(query, true); + Assert.AreEqual(1, result.GetBindings().Count()); + + query = new SparqlQuery("ASK WHERE { nco:hasContactMedium . }"); + + result = Model.ExecuteQuery(query); + Assert.IsFalse(result.GetAnwser()); + + result = Model.ExecuteQuery(query, true); + Assert.IsTrue(result.GetAnwser()); + + query = new SparqlQuery("DESCRIBE ?element WHERE { ?element nco:hasContactMedium . }"); + + result = Model.ExecuteQuery(query); + Assert.AreEqual(0, result.GetResources().Count()); + + result = Model.ExecuteQuery(query, true); + Assert.AreEqual(1, result.GetResources().Count()); + + // The original test failed because Virtuoso ORDER BY on DATETIME values fails with DESCRIBE query forms. + // See: https://github.com/openlink/virtuoso-opensource/issues/23 + query = new SparqlQuery("SELECT ?date WHERE { ?m rdf:type nco:ContactMedium ; nco:creator ; dc:date ?date . } ORDER BY ASC(?date)"); + result = Model.ExecuteQuery(query, true); + + List bindings = result.GetBindings().ToList(); + + Assert.AreEqual(3, bindings.Count); + + DateTime? d0 = null; + + foreach (BindingSet b in bindings) + { + var d1 = (DateTime)b["date"]; + + if (d0 != null) + { + Assert.Greater(d1, d0); + } + + d0 = d1; + } + } + + [Test] + public void TestModelApi() + { + // Retrieving resources using the model API. + Assert.AreEqual(true, Model.ContainsResource(new Uri("http://example.org/Hans"))); + Assert.AreEqual(false, Model.ContainsResource(new Uri("http://example.org/Peter"))); + + IResource hans = Model.GetResource(new Uri("http://example.org/Hans")); + Assert.Throws(delegate { Model.GetResource(new Uri("http://example.org/Peter")); }); + + hans = Model.GetResource(new Uri("http://example.org/Hans"), typeof(Resource)) as IResource; + Assert.NotNull(hans); + } + + [Test] + public void TestEscaping() + { + SparqlQuery query = new SparqlQuery(@" + SELECT ?s ?p ?o WHERE + { + ?s ?p ""Hello World"" . + ?s ?p ""'Hello World'"" . + ?s ?p '''Hello + World''' . + ?s ?p 'C:\\Directory\\file.ext' . + }"); + + string queryString = query.ToString(); + + Assert.IsTrue(queryString.Contains('\n')); + Assert.IsTrue(queryString.Contains("\\\\")); + Assert.IsTrue(queryString.Contains("\\'")); + } + + [Test] + public void TestUriEscaping() + { + Uri uri = new Uri("file:///F:/test/02%20-%20Take%20Me%20Somewhere%20Nice.mp3"); + var x = Model.CreateResource(uri); + var nameProperty = new Property(new Uri("ex:name")); + x.AddProperty(nameProperty, "Name"); + x.Commit(); + + var result = Model.GetResource(uri); + Assert.AreEqual(x.Uri, result.Uri); + Assert.AreEqual(x, result); + } + + [Test] + public void TestQueryParameters() + { + SparqlQuery query = new SparqlQuery(@"SELECT ?s WHERE { ?s ?p ?o . ?s ?p @someValue . }"); + + query.Bind("@someValue", "Value"); + + string queryString = query.ToString(); + + Assert.IsFalse(string.IsNullOrEmpty(queryString)); + + query = new SparqlQuery(@"SELECT ?s WHERE { ?s ?p 'Hallo'@de . }"); + + queryString = query.ToString(); + + Assert.AreEqual(queryString, @"SELECT ?s WHERE { ?s ?p 'Hallo'@de . }"); + + query = new SparqlQuery(@"SELECT ?s WHERE { ?s ?p 'Hallo'@de-de . }"); + + queryString = query.ToString(); + + Assert.AreEqual(queryString, @"SELECT ?s WHERE { ?s ?p 'Hallo'@de-de . }"); + } + + [Test] + public void TestSelectCount() + { + SparqlQuery query = new SparqlQuery("SELECT ( COUNT(?s) AS ?count ) WHERE { ?s rdf:type nco:PhoneNumber. }"); + ISparqlQueryResult result = Model.ExecuteQuery(query); + + var bindings = result.GetBindings(); + Assert.AreEqual(1, bindings.Count()); + Assert.AreEqual(2, bindings.First()["count"]); + } + + [Test] + public void TestCount() + { + SparqlQuery query = new SparqlQuery("SELECT ?s ?p ?o WHERE { ?s ?p ?o. ?s rdf:type nco:PhoneNumber. }"); + ISparqlQueryResult result = Model.ExecuteQuery(query); + + Assert.AreEqual(2, result.Count()); + + query = new SparqlQuery("SELECT ?s ?p ?o WHERE { ?s ?p ?o. ?s rdf:type nco:PhoneNumber. }"); + result = Model.ExecuteQuery(query); + + Assert.AreEqual(2, result.Count()); + } + + [Test] + public void TestSetModel() + { + Regex expression = new Regex(Regex.Escape("FROM")); + + SparqlQuery query = new SparqlQuery("SELECT COUNT(?s) AS ?count WHERE { ?s ?p ?o . }"); + + Assert.IsNull(query.Model); + Assert.AreEqual(0, expression.Matches(query.ToString()).Count); + + query.Model = Model; + + Assert.NotNull(query.Model); + Assert.AreEqual(1, expression.Matches(query.ToString()).Count); + + SparqlQuery query2 = new SparqlQuery("ASK FROM WHERE { ?s ?p ?o . }"); + + Assert.IsNull(query2.Model); + Assert.AreEqual(1, expression.Matches(query2.ToString()).Count); + + query2.Model = Model; + + Assert.IsNotNull(query2.Model); + Assert.AreEqual(1, expression.Matches(query2.ToString()).Count); + + SparqlQuery query3 = new SparqlQuery("ASK FROM @graph WHERE { ?s ?p ?o . }"); + query3.Bind("@graph", Model); + + Assert.IsNull(query3.Model); + Assert.AreEqual(1, expression.Matches(query3.ToString()).Count); + + query3.Model = Model; + + Assert.IsNotNull(query3.Model); + Assert.AreEqual(1, expression.Matches(query3.ToString()).Count); + + SparqlQuery query4 = new SparqlQuery("ASK FROM @graph WHERE { ?s ?p ?o . }"); + query4.Model = Model; + + Assert.IsNotNull(query4.Model); + + Assert.Throws(delegate { query4.Bind("@graph", Model); }); + } + + [Test] + public void TestSetLimit() + { + SparqlQuery query = new SparqlQuery(@" + SELECT ?s0 ?p0 ?o0 WHERE + { + ?s0 ?p0 ?o0 . + { + SELECT DISTINCT ?s0 WHERE + { + ?s ?p ?o. + ?s @type @class . + + { + ?s ?p1 ?o1 . + FILTER ISLITERAL(?o1) . FILTER REGEX(STR(?o1), '', 'i') . + } + UNION + { + ?s ?p1 ?s1 . + ?s1 ?p2 ?o2 . + FILTER ISLITERAL(?o2) . FILTER REGEX(STR(?o2), '', 'i') . + } + } + ORDER BY ?o + } + }"); + + query.Bind("@type", rdf.type); + query.Bind("@class", tmo.Task); + + MethodInfo method = query.GetType().GetMethod("SetLimit", BindingFlags.NonPublic | BindingFlags.Instance); + method.Invoke(query, new object[] { 10 }); + + ISparqlQueryResult result = Model.ExecuteQuery(query); + + List resources = result.GetResources().ToList(); + } + + [Test] + public void TestModelGroup() + { + Uri modelUri1 = new Uri("http://example.org/TestModel1"); + Uri modelUri2 = new Uri("http://example.org/TestModel2"); + IModelGroup g = Store.CreateModelGroup(modelUri1, modelUri2); + var query = new SparqlQuery("PREFIX nco: SELECT ?s ?p ?o WHERE { ?s ?p ?o. ?s nco:fullname 'Hans Wurscht'. }"); + query.Model = g; + var x = query.ToString(); + + + } + } +} diff --git a/tests/Trinity.Tests.Fuseki/SparqlUpdateTest.cs b/tests/Trinity.Tests.Fuseki/SparqlUpdateTest.cs new file mode 100644 index 00000000..eed6125c --- /dev/null +++ b/tests/Trinity.Tests.Fuseki/SparqlUpdateTest.cs @@ -0,0 +1,205 @@ +// LICENSE: +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +// AUTHORS: +// +// Moritz Eberl +// Sebastian Faubel +// +// Copyright (c) Semiodesk GmbH 2015-2019 + +using System; +using System.Linq; +using NUnit.Framework; + +namespace Semiodesk.Trinity.Test.Fuseki +{ + [TestFixture] + public class SparqlUpdateTest : SetupClass + { + private IStore _store; + + private IModel _model = null; + + [SetUp] + public void SetUp() + { + string connectionString = SetupClass.ConnectionString; + + _store = StoreFactory.CreateStore(string.Format("{0};rule=urn:semiodesk/test/ruleset", connectionString)); + _model = _store.GetModel(new Uri("ex:TestModel")); + + if (!_model.IsEmpty) + { + _model.Clear(); + } + + OntologyDiscovery.AddNamespace("vcard", new Uri("http://www.w3.org/2001/vcard-rdf/3.0#")); + OntologyDiscovery.AddNamespace("foaf", new Uri("http://xmlns.com/foaf/0.1/")); + OntologyDiscovery.AddNamespace("dc", new Uri("http://purl.org/dc/elements/1.1/")); + OntologyDiscovery.AddNamespace("ex", new Uri("http://example.org/")); + } + + [TearDown] + public void TearDown() + { + _model.Clear(); + _store.Dispose(); + } + + [Test] + public void TestInsert() + { + SparqlUpdate update = new SparqlUpdate(@"INSERT DATA { GRAPH { ex:book dc:title 'This is an example title' . } }"); + + _model.ExecuteUpdate(update); + + SparqlQuery query = new SparqlQuery(@"ASK WHERE { ?s dc:title 'This is an example title' . }"); + + ISparqlQueryResult result = _model.ExecuteQuery(query); + + Assert.AreEqual(true, result.GetAnwser()); + + /// TEST WITH LANGUAGE TAG + /// + update = new SparqlUpdate(@"INSERT DATA { GRAPH { ex:book dc:title 'This is an example title'@en . } }"); + + _model.ExecuteUpdate(update); + + query = new SparqlQuery(@"ASK WHERE { ?s dc:title 'This is an example title'@en . }"); + + result = _model.ExecuteQuery(query); + + Assert.AreEqual(true, result.GetAnwser()); + } + + [Test] + public void TestModify() + { + SparqlUpdate update = new SparqlUpdate(@" + INSERT DATA { GRAPH { ex:book dc:title 'This is an example title' . } }"); + + _model.ExecuteUpdate(update); + + update = new SparqlUpdate(@" + DELETE DATA { GRAPH { ex:book dc:title 'This is an example title' . } }; + INSERT DATA { GRAPH { ex:book dc:title 'This is an example title too' . } }"); + + _model.ExecuteUpdate(update); + + SparqlQuery query = new SparqlQuery(@" + ASK WHERE { ?s dc:title 'This is an example title' . }"); + + Assert.AreEqual(false, _model.ExecuteQuery(query).GetAnwser()); + + query = new SparqlQuery(@" + ASK WHERE { ?s dc:title 'This is an example title too' . }"); + + Assert.AreEqual(true, _model.ExecuteQuery(query).GetAnwser()); + } + + [Test] + public void TestMultipleModify() + { + SparqlUpdate update = new SparqlUpdate(@" + INSERT DATA { GRAPH { ex:book dc:title 'This is an example title' . } }; + INSERT DATA { GRAPH { ex:book2 dc:title 'This is an example title2' . } }"); + + _model.ExecuteUpdate(update); + + SparqlQuery query = new SparqlQuery(@" + ASK WHERE { ?s dc:title 'This is an example title' . }"); + + Assert.AreEqual(true, _model.ExecuteQuery(query).GetAnwser()); + + query = new SparqlQuery(@" + ASK WHERE { ?s dc:title 'This is an example title2' . }"); + + Assert.AreEqual(true, _model.ExecuteQuery(query).GetAnwser()); + } + + + [Test] + public void TestDelete() + { + SparqlUpdate update = new SparqlUpdate(@" + INSERT DATA { GRAPH { ex:book dc:title 'This is an example title' . } }"); + + _model.ExecuteUpdate(update); + + update = new SparqlUpdate(@" + DELETE DATA { GRAPH { ex:book dc:title 'This is an example title' . } }"); + + _model.ExecuteUpdate(update); + + SparqlQuery query = new SparqlQuery(@" + ASK WHERE { ?s dc:title 'This is an example title' . }"); + + Assert.AreEqual(false, _model.ExecuteQuery(query).GetAnwser()); + } + + [Test] + public void TestLoad() + { + Assert.Inconclusive(); + SparqlUpdate update = new SparqlUpdate(@"LOAD INTO "); + + _model.ExecuteUpdate(update); + + SparqlQuery query = new SparqlQuery(@"SELECT * WHERE { ?s ?p ?o . }"); + + Assert.Greater(_model.ExecuteQuery(query).GetBindings().Count(), 0); + } + + [Test] + public void TestClear() + { + SparqlUpdate update = new SparqlUpdate(@"INSERT DATA { GRAPH { ex:book dc:title 'This is an example title' . } }"); + + _model.ExecuteUpdate(update); + + update = new SparqlUpdate(@"CLEAR GRAPH "); + + _model.ExecuteUpdate(update); + + SparqlQuery query = new SparqlQuery(@"ASK WHERE { ?s dc:title 'This is an example title' . }"); + + Assert.AreEqual(false, _model.ExecuteQuery(query).GetAnwser()); + } + + [Test] + public void TestUpdateParameters() + { + SparqlUpdate update = new SparqlUpdate(@" + DELETE { ?s ?p @oldValue . } + INSERT { ?s ?p @newValue . } + WHERE { ?s ?p ?o . }"); + + update.Bind("@oldValue", "Fail"); + update.Bind("@newValue", "Success"); + + string updateString = update.ToString(); + + Assert.IsFalse(string.IsNullOrEmpty(updateString)); + + _model.ExecuteUpdate(update); + } + } +} diff --git a/tests/Trinity.Tests.Fuseki/StoreProviderTest.cs b/tests/Trinity.Tests.Fuseki/StoreProviderTest.cs new file mode 100644 index 00000000..777d9be2 --- /dev/null +++ b/tests/Trinity.Tests.Fuseki/StoreProviderTest.cs @@ -0,0 +1,21 @@ +using NUnit.Framework; +using Semiodesk.Trinity.Store.Fuseki; + +namespace Semiodesk.Trinity.Test.Fuseki +{ + [TestFixture] + public class StoreProviderTest : SetupClass + { + + [Test] + public void FusekiConfigurationStringTest() + { + + string connectionString = string.Format("provider=fuseki;host=http://localhost:3000;dataset=ds"); + IStore anObject = StoreFactory.CreateStore(connectionString); + Assert.IsNotNull(anObject); + Assert.IsInstanceOf(anObject); + anObject.Dispose(); + } + } +} diff --git a/tests/Trinity.Tests.Fuseki/Trinity.Tests.Fuseki.csproj b/tests/Trinity.Tests.Fuseki/Trinity.Tests.Fuseki.csproj new file mode 100644 index 00000000..5de28644 --- /dev/null +++ b/tests/Trinity.Tests.Fuseki/Trinity.Tests.Fuseki.csproj @@ -0,0 +1,57 @@ + + + + net472 + Trinity.Test.Virtuoso + Copyright © Semiodesk GmbH 2019 + + Semiodesk GmbH + 1.0.0.8 + 1.0.0.8 + 1.0.0.8 + Semiodesk.Trinity.Tests.Virtuoso + Semiodesk.Trinity.Tests.Virtuoso + Exe + + false + + + + + + + + + + + + + + + + + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + + diff --git a/tests/Trinity.Tests.Fuseki/ontologies.config b/tests/Trinity.Tests.Fuseki/ontologies.config new file mode 100644 index 00000000..c1d88fbe --- /dev/null +++ b/tests/Trinity.Tests.Fuseki/ontologies.config @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/Trinity.Tests.Fuseki/ontologies/foaf.rdf b/tests/Trinity.Tests.Fuseki/ontologies/foaf.rdf new file mode 100644 index 00000000..68d0700c --- /dev/null +++ b/tests/Trinity.Tests.Fuseki/ontologies/foaf.rdf @@ -0,0 +1,609 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Label Property + A foaf:LabelProperty is any RDF property with texual values that serve as labels. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/Trinity.Tests.Fuseki/ontologies/nco.trig b/tests/Trinity.Tests.Fuseki/ontologies/nco.trig new file mode 100644 index 00000000..c7b560c9 --- /dev/null +++ b/tests/Trinity.Tests.Fuseki/ontologies/nco.trig @@ -0,0 +1,811 @@ +# +# Copyright (c) 2007 NEPOMUK Consortium +# Copyright (c) 2009-2011 Sebastian Trueg +# +# All rights reserved, licensed under either CC-BY or BSD. +# +# You are free: +# * to Share - to copy, distribute and transmit the work +# * to Remix - to adapt the work +# Under the following conditions: +# * Attribution - You must attribute the work in the manner specified by the author +# or licensor (but not in any way that suggests that they endorse you or your use +# of the work). +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this +# list of conditions and the following disclaimer in the documentation and/or +# other materials provided with the distribution. +# * Neither the names of the authors nor the names of contributors may +# be used to endorse or promote products derived from this ontology without +# specific prior written permission. +# +# THIS ONTOLOGY IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS ONTOLOGY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +@prefix exif: . +@prefix nid3: . +@prefix nrl: . +@prefix nfo: . +@prefix xsd: . +@prefix tmo: . +@prefix protege: . +@prefix nmo: . +@prefix rdfs: . +@prefix nexif: . +@prefix ncal: . +@prefix pimo: . +@prefix dcterms: . +@prefix nao: . +@prefix geo: . +@prefix dc: . +@prefix nie: . +@prefix nco: . +@prefix rdf: . + +nco: {nco:region + a rdf:Property ; + rdfs:comment "Region. Inspired by the fifth part of the value of the 'ADR' property as defined in RFC 2426, sec. 3.2.1" ; + rdfs:domain nco:PostalAddress ; + rdfs:label "region" ; + rdfs:range xsd:string ; + nrl:maxCardinality 1 . + + nco:key + a rdf:Property ; + rdfs:comment "An encryption key attached to a contact. Inspired by the KEY property defined in RFC 2426 sec. 3.7.2" ; + rdfs:domain nco:Contact ; + rdfs:label "key" ; + rdfs:range nie:DataObject ; + rdfs:subPropertyOf nie:hasPart . + + nco:nameHonorificSuffix + a rdf:Property ; + rdfs:comment "A suffix for the name of the Object represented by the given object. See documentation for the 'nameFamily' for details." ; + rdfs:domain nco:PersonContact ; + rdfs:label "nameHonorificSuffix" ; + rdfs:range xsd:string . + + nco:url + a rdf:Property, nrl:DefiningProperty ; + rdfs:comment "A uniform resource locator associated with the given role of a Contact. Inspired by the 'URL' property defined in RFC 2426 Sec. 3.6.8." ; + rdfs:domain nco:Role ; + rdfs:label "url" ; + rdfs:range rdfs:Resource . + + nco:VoicePhoneNumber + a rdfs:Class ; + rdfs:comment "A telephone number with voice communication capabilities. Class inspired by the TYPE=voice parameter of the TEL property defined in RFC 2426 sec. 3.3.1" ; + rdfs:label "VoicePhoneNumber" ; + rdfs:subClassOf nco:PhoneNumber . + + nco:nameFamily + a rdf:Property ; + rdfs:comment "The family name of an Object represented by this Contact. These applies to people that have more than one given name. The 'first' one is considered 'the' given name (see nameGiven) property. All additional ones are considered 'additional' names. The name inherited from parents is the 'family name'. e.g. For Dr. John Phil Paul Stevenson Jr. M.D. A.C.P. we have contact with: honorificPrefix: 'Dr.', nameGiven: 'John', nameAdditional: 'Phil', nameAdditional: 'Paul', nameFamily: 'Stevenson', honorificSuffix: 'Jr.', honorificSuffix: 'M.D.', honorificSuffix: 'A.C.P.'. These properties form an equivalent of the compound 'N' property as defined in RFC 2426 Sec. 3.1.2" ; + rdfs:domain nco:PersonContact ; + rdfs:label "nameFamily" ; + rdfs:range xsd:string ; + nrl:maxCardinality "1" . + + nco:VideoTelephoneNumber + a rdfs:Class ; + rdfs:comment "A Video telephone number. A class inspired by the TYPE=video parameter of the TEL property defined in RFC 2426 sec. 3.3.1" ; + rdfs:label "VideoTelephoneNumber" ; + rdfs:subClassOf nco:VoicePhoneNumber . + + nco:contactUID + a rdf:Property ; + rdfs:comment "A value that represents a globally unique identifier corresponding to the individual or resource associated with the Contact. An equivalent of the 'UID' property defined in RFC 2426 Sec. 3.6.7" ; + rdfs:domain nco:Contact ; + rdfs:label "contactUID" ; + rdfs:range xsd:string ; + rdfs:subPropertyOf nie:identifier ; + nrl:maxCardinality "1" . + + nco:publisher + a rdf:Property, nrl:DefiningProperty ; + rdfs:comment "An entity responsible for making the InformationElement available." ; + rdfs:domain nie:InformationElement ; + rdfs:label "publisher" ; + rdfs:range nco:Contact ; + rdfs:subPropertyOf dc:publisher . + + nco:country + a rdf:Property ; + rdfs:comment "A part of an address specyfing the country. Inspired by the seventh part of the value of the 'ADR' property as defined in RFC 2426, sec. 3.2.1" ; + rdfs:domain nco:PostalAddress ; + rdfs:label "country" ; + rdfs:range xsd:string ; + nrl:maxCardinality 1 . + + nco:nameHonorificPrefix + a rdf:Property ; + rdfs:comment "A prefix for the name of the object represented by this Contact. See documentation for the 'nameFamily' property for details." ; + rdfs:domain nco:PersonContact ; + rdfs:label "nameHonorificPrefix" ; + rdfs:range xsd:string . + + nco:extendedAddress + a rdf:Property ; + rdfs:comment "An extended part of an address. This field might be used to express parts of an address that aren't include in the name of the Contact but also aren't part of the actual location. Usually the streed address and following fields are enough for a postal letter to arrive. Examples may include ('University of California Campus building 45', 'Sears Tower 34th floor' etc.) Inspired by the second part of the value of the 'ADR' property as defined in RFC 2426, sec. 3.2.1" ; + rdfs:domain nco:PostalAddress ; + rdfs:label "extendedAddress" ; + rdfs:range xsd:string ; + nrl:maxCardinality "1" . + + nco:IMAccount + a rdfs:Class ; + rdfs:comment "An account in an Instant Messaging system." ; + rdfs:label "IMAccount" ; + rdfs:subClassOf nco:ContactMedium . + + nco:hasIMAccount + a rdf:Property ; + rdfs:comment "Indicates that an Instant Messaging account owned by an entity represented by this contact." ; + rdfs:domain nco:Role ; + rdfs:label "hasIMAccount" ; + rdfs:range nco:IMAccount ; + rdfs:subPropertyOf nco:hasContactMedium . + + nco:IsdnNumber + a rdfs:Class ; + rdfs:comment "An ISDN phone number. Inspired by the (TYPE=isdn) parameter of the TEL property as defined in RFC 2426 sec 3.3.1." ; + rdfs:label "IsdnNumber" ; + rdfs:subClassOf nco:VoicePhoneNumber . + + nco:creator + a rdf:Property, nrl:DefiningProperty ; + rdfs:comment "Creator of an information element, an entity primarily responsible for the creation of the content of the data object." ; + rdfs:domain nie:InformationElement ; + rdfs:label "creator" ; + rdfs:range nco:Contact ; + rdfs:subPropertyOf dc:creator , nco:contributor , nao:creator . + + nco:hasLocation + a rdf:Property ; + rdfs:comment "Geographical location of the contact. Inspired by the 'GEO' property specified in RFC 2426 Sec. 3.4.2" ; + rdfs:domain nco:Contact ; + rdfs:label "hasLocation" ; + rdfs:range geo:Point ; + nrl:maxCardinality "1" . + + nco:birthday + a rdf:Property ; + rdfs:comment "Links a contact with the calendar event of his birthday. (NCAL version)"; + rdfs:label "birthday" ; + rdfs:domain nco:Contact ; + rdfs:range ncal:BirthdayEvent ; + nrl:maxCardinality "1" . + + nco:phoneNumber + a rdf:Property ; + rdfs:domain nco:PhoneNumber ; + rdfs:label "phoneNumber" ; + rdfs:range xsd:string ; + nrl:maxCardinality "1" . + + nco:nickname + a rdf:Property ; + rdfs:comment "A nickname of the Object represented by this Contact. This is an equivalent of the 'NICKNAME' property as defined in RFC 2426 Sec. 3.1.3." ; + rdfs:domain nco:Contact ; + rdfs:label "nickname" ; + rdfs:range xsd:string . + + nco:imStatus + a rdf:Property, nrl:NonDefiningProperty ; + rdfs:comment "Current status of the given IM account. When this property is set, the nco:imStatusType should also always be set. Applications should attempt to parse this property to determine the presence, only falling back to the nco:imStatusType property in the case that this property's value is unrecognised. Values for this property may include 'available', 'offline', 'busy' etc. The exact choice of them is unspecified, although it is recommended to follow the guidance of the Telepathy project when choosing a string identifier http://telepathy.freedesktop.org/spec/Connection_Interface_Simple_Presence.html#description" ; + rdfs:domain nco:IMAccount ; + rdfs:label "imStatus" ; + rdfs:range xsd:string ; + nrl:maxCardinality 1 . + + nco:imStatusType + a rdf:Property ; + rdfs:comment "Current status type of the given IM account. When this property is set, the nco:imStatus property should also always be set. Applications should attempt to parse the nco:imStatus property to determine the presence, only falling back to this property in the case that the nco:imStatus property's value is unrecognised." ; + rdfs:domain nco:IMAccount ; + rdfs:label "instant messaging status type" ; + rdfs:range nco:IMStatusType ; + nrl:maxCardinality 1 . + + nco:IMStatusType a rdfs:Class ; + rdfs:label "instant messaging status type" ; + rdfs:comment "The status type of an IMAccount. Based on the Connection_Presence_Type enumeration of the Telepathy project: http://telepathy.freedesktop.org/spec/Connection_Interface_Simple_Presence.html#Enum:Connection_Presence_Type" ; + rdfs:subClassOf rdfs:Resource . + + nco:IMStatusTypeOffline + a nco:IMStatusType ; + rdfs:label "offline" . + + nco:IMStatusTypeAvailable + a nco:IMStatusType ; + rdfs:label "available" . + + nco:IMStatusTypeAway + a nco:IMStatusType ; + rdfs:label "away" . + + nco:IMStatusTypeExtendedAway + a nco:IMStatusType ; + rdfs:label "extended away". + + nco:IMStatusTypeHidden + a nco:IMStatusType ; + rdfs:label "hidden" . + + nco:IMStatusTypeBusy + a nco:IMStatusType ; + rdfs:label "busy" . + + nco:IMStatusTypeUnknown + a nco:IMStatusType ; + rdfs:label "unknown" . + + nco:containsContact + a rdf:Property, nrl:DefiningProperty ; + rdfs:comment """A property used to group contacts into contact groups. This + property was NOT defined in the VCARD standard. See documentation for the + 'ContactList' class for details""" ; + rdfs:domain nco:ContactList ; + rdfs:label "containsContact" ; + rdfs:range nco:ContactListDataObject ; + rdfs:subPropertyOf nie:hasPart . + + nco:department + a rdf:Property ; + rdfs:comment "Department. The organizational unit within the organization." ; + rdfs:domain nco:Affiliation ; + rdfs:label "department" ; + rdfs:range xsd:string . + + nco:imID + a rdf:Property ; + rdfs:comment "Identifier of the IM account. Examples of such identifier might include ICQ UINs, Jabber IDs, Skype names etc." ; + rdfs:domain nco:IMAccount ; + rdfs:label "imID" ; + rdfs:range xsd:string ; + rdfs:subPropertyOf nao:identifier . + + nco:addressLocation + a rdf:Property, nrl:DefiningProperty ; + rdfs:comment "The geographical location of a postal address." ; + rdfs:domain nco:PostalAddress ; + rdfs:label "addressLocation" ; + rdfs:range geo:Point ; + nrl:maxCardinality "1" . + + nco:note + a rdf:Property ; + rdfs:comment "A note about the object represented by this Contact. An equivalent for the 'NOTE' property defined in RFC 2426 Sec. 3.6.2" ; + rdfs:domain nco:Contact ; + rdfs:label "note" ; + rdfs:range xsd:string ; + rdfs:subPropertyOf nie:description . + + nco:representative + a rdf:Property, nrl:DefiningProperty ; + rdfs:comment "An object that represent an object represented by this Contact. Usually this property is used to link a Contact to an organization, to a contact to the representative of this organization the user directly interacts with. An equivalent for the 'AGENT' property defined in RFC 2426 Sec. 3.5.4" ; + rdfs:domain nco:Contact ; + rdfs:label "representative" ; + rdfs:range nco:Contact . + + nco:nameAdditional + a rdf:Property ; + rdfs:comment "Additional given name of an object represented by this contact. See documentation for 'nameFamily' property for details." ; + rdfs:domain nco:PersonContact ; + rdfs:label "nameAdditional" ; + rdfs:range xsd:string . + + nco:nameGiven + a rdf:Property ; + rdfs:comment "The given name for the object represented by this Contact. See documentation for 'nameFamily' property for details." ; + rdfs:domain nco:PersonContact ; + rdfs:label "nameGiven" ; + rdfs:range xsd:string ; + nrl:maxCardinality "1" . + + nco:PcsNumber + a rdfs:Class ; + rdfs:comment "Personal Communication Services Number. A class inspired by the TYPE=pcs parameter of the TEL property defined in RFC 2426 sec. 3.3.1" ; + rdfs:label "PcsNumber" ; + rdfs:subClassOf nco:VoicePhoneNumber . + + nco:ContactList + a rdfs:Class ; + rdfs:comment "A contact list, this class represents an addressbook or a contact list of an IM application. Contacts inside a contact list can belong to contact groups." ; + rdfs:label "ContactList" ; + rdfs:subClassOf nie:InformationElement . + + nco:fullname + a rdf:Property ; + rdfs:comment "To specify the formatted text corresponding to the name of the object the Contact represents. An equivalent of the FN property as defined in RFC 2426 Sec. 3.1.1." ; + rdfs:domain nco:Contact ; + rdfs:label "fullname" ; + rdfs:range xsd:string ; + nrl:maxCardinality "1" ; + rdfs:subPropertyOf nie:title . + + nco:ContactGroup + a rdfs:Class ; + rdfs:comment "A group of Contacts. Could be used to express a group in an addressbook or on a contact list of an IM application. One contact can belong to many groups." ; + rdfs:label "ContactGroup" ; + rdfs:subClassOf nie:InformationElement . + + nco:BbsNumber + a rdfs:Class ; + rdfs:comment "A Bulletin Board System (BBS) phone number. Inspired by the (TYPE=bbsl) parameter of the TEL property as defined in RFC 2426 sec 3.3.1." ; + rdfs:label "BbsNumber" ; + rdfs:subClassOf nco:ModemNumber . + + nco:Affiliation + a rdfs:Class ; + rdfs:comment "Aggregates three properties defined in RFC2426. Originally all three were attached directly to a person. One person could have only one title and one role within one organization. This class is intended to lift this limitation." ; + rdfs:label "Affiliation" ; + rdfs:subClassOf nco:Role . + + nco:streetAddress + a rdf:Property ; + rdfs:comment "The streed address. Inspired by the third part of the value of the 'ADR' property as defined in RFC 2426, sec. 3.2.1" ; + rdfs:domain nco:PostalAddress ; + rdfs:label "streetAddress" ; + rdfs:range xsd:string ; + nrl:maxCardinality "1" . + + nco:OrganizationContact + a rdfs:Class ; + rdfs:comment "A Contact that denotes on Organization." ; + rdfs:label "OrganizationContact" ; + rdfs:subClassOf nco:Contact . + + nco:PhoneNumber + a rdfs:Class ; + rdfs:comment "A telephone number." ; + rdfs:label "PhoneNumber" ; + rdfs:subClassOf nco:ContactMedium . + + nco:Contact + a rdfs:Class ; + rdfs:comment "A Contact. A piece of data that can provide means to identify or communicate with an entity." ; + rdfs:label "Contact" ; + rdfs:subClassOf nco:Role , nie:InformationElement , nao:Party . + + nco:ModemNumber + a rdfs:Class ; + rdfs:comment "A modem phone number. Inspired by the (TYPE=modem) parameter of the TEL property as defined in RFC 2426 sec 3.3.1." ; + rdfs:label "ModemNumber" ; + rdfs:subClassOf nco:PhoneNumber . + + nco:Role + a rdfs:Class ; + rdfs:comment "A role played by a contact. Contacts that denote people, can have many roles (e.g. see the hasAffiliation property and Affiliation class). Contacts that denote Organizations or other Agents usually have one role. Each role can introduce additional contact media." ; + rdfs:label "Role" ; + rdfs:subClassOf rdfs:Resource . + + nco:PagerNumber + a rdfs:Class ; + rdfs:comment "A pager phone number. Inspired by the (TYPE=pager) parameter of the TEL property as defined in RFC 2426 sec 3.3.1." ; + rdfs:label "PagerNumber" ; + rdfs:subClassOf nco:MessagingNumber . + + nco:hasPhoneNumber + a rdf:Property ; + rdfs:comment "A number for telephony communication with the object represented by this Contact. An equivalent of the 'TEL' property defined in RFC 2426 Sec. 3.3.1" ; + rdfs:domain nco:Role ; + rdfs:label "hasPhoneNumber" ; + rdfs:range nco:PhoneNumber ; + rdfs:subPropertyOf nco:hasContactMedium . + + nco:photo + a rdf:Property ; + rdfs:comment "Photograph attached to a Contact. The DataObject referred to by this property is usually interpreted as an nfo:Image. Inspired by the PHOTO property defined in RFC 2426 sec. 3.1.4" ; + rdfs:domain nco:Contact ; + rdfs:label "photo" ; + rdfs:range nie:DataObject ; + rdfs:subPropertyOf nie:hasPart . + + nco:contributor + a rdf:Property, nrl:DefiningProperty ; + rdfs:comment "An entity responsible for making contributions to the content of the InformationElement." ; + rdfs:domain nie:InformationElement ; + rdfs:label "contributor" ; + rdfs:range nco:Contact ; + rdfs:subPropertyOf dc:contributor , nao:contributor . + + nco:logo + a rdf:Property ; + rdfs:comment "Logo of a company. Inspired by the LOGO property defined in RFC 2426 sec. 3.5.3" ; + rdfs:domain nco:OrganizationContact ; + rdfs:label "logo" ; + rdfs:range nie:DataObject ; + rdfs:subPropertyOf nie:hasPart . + + nco:websiteUrl + a rdf:Property ; + rdfs:comment "A url of a website." ; + rdfs:domain nco:Role ; + rdfs:label "websiteUrl" ; + rdfs:range rdfs:Resource ; + rdfs:subPropertyOf nco:url . + + nco:ContactMedium + a rdfs:Class ; + rdfs:comment "A superclass for all contact media - ways to contact an entity represented by a Contact instance. Some of the subclasses of this class (the various kinds of telephone numbers and postal addresses) have been inspired by the values of the TYPE parameter of ADR and TEL properties defined in RFC 2426 sec. 3.2.1. and 3.3.1 respectively. Each value is represented by an appropriate subclass with two major exceptions TYPE=home and TYPE=work. They are to be expressed by the roles these contact media are attached to i.e. contact media with TYPE=home parameter are to be attached to the default role (nco:Contact or nco:PersonContact), whereas media with TYPE=work parameter should be attached to nco:Affiliation or nco:OrganizationContact." ; + rdfs:label "ContactMedium" ; + rdfs:subClassOf rdfs:Resource . + + nco:Gender + a rdfs:Class ; + rdfs:comment "Gender. Instances of this class may include male and female." ; + rdfs:label "Gender" ; + rdfs:subClassOf rdfs:Resource . + + nco:male + a nco:Gender ; + rdfs:comment "A Male" ; + rdfs:label "male" . + + nco:birthDate + a rdf:Property ; + rdfs:comment "Birth date of the object represented by this Contact. An equivalent of the 'BDAY' property as defined in RFC 2426 Sec. 3.1.5." ; + rdfs:domain nco:Contact ; + rdfs:label "birthDate" ; + rdfs:range xsd:date ; + rdfs:subPropertyOf dc:date ; + nrl:maxCardinality 1 . + + nco:hasEmailAddress + a rdf:Property ; + rdfs:comment "An address for electronic mail communication with the object specified by this contact. An equivalent of the 'EMAIL' property as defined in RFC 2426 Sec. 3.3.1." ; + rdfs:domain nco:Role ; + rdfs:label "hasEmailAddress" ; + rdfs:range nco:EmailAddress ; + rdfs:subPropertyOf nco:hasContactMedium . + + nco:postalcode + a rdf:Property ; + rdfs:comment "Postal Code. Inspired by the sixth part of the value of the 'ADR' property as defined in RFC 2426, sec. 3.2.1" ; + rdfs:domain nco:PostalAddress ; + rdfs:label "postalcode" ; + rdfs:range xsd:string ; + nrl:maxCardinality 1 . + + nco:MessagingNumber + a rdfs:Class ; + rdfs:comment "A number that can accept textual messages." ; + rdfs:label "MessagingNumber" ; + rdfs:subClassOf nco:PhoneNumber . + + nco:org + a rdf:Property, nrl:DefiningProperty ; + rdfs:comment "Name of an organization or a unit within an organization the object represented by a Contact is associated with. An equivalent of the 'ORG' property defined in RFC 2426 Sec. 3.5.5" ; + rdfs:domain nco:Affiliation ; + rdfs:label "org" ; + rdfs:range nco:OrganizationContact ; + nrl:maxCardinality "1" . + + nco:PersonContact + a rdfs:Class ; + rdfs:comment "A Contact that denotes a Person. A person can have multiple Affiliations." ; + rdfs:label "PersonContact" ; + rdfs:subClassOf nco:Contact . + + nco:ParcelDeliveryAddress + a rdfs:Class ; + rdfs:comment "Parcel Delivery Addresse. Class inspired by TYPE=parcel parameter of the ADR property defined in RFC 2426 sec. 3.2.1" ; + rdfs:label "ParcelDeliveryAddress" ; + rdfs:subClassOf nco:PostalAddress . + + nco:title + a rdf:Property ; + rdfs:comment "The official title the object represented by this contact in an organization. E.g. 'CEO', 'Director, Research and Development', 'Junior Software Developer/Analyst' etc. An equivalent of the 'TITLE' property defined in RFC 2426 Sec. 3.5.1" ; + rdfs:domain nco:Affiliation ; + rdfs:label "title" ; + rdfs:range xsd:string ; + nrl:maxCardinality "1" . + + nco:AudioIMAccount + a rdfs:Class ; + nao:deprecated true ; + rdfs:comment "Deprecated in favour of nco:imCapabilityAudio." ; + rdfs:label "AudioIMAccount" ; + rdfs:subClassOf nco:IMAccount . + + nco:voiceMail + a rdf:Property ; + rdfs:comment "Indicates if the given number accepts voice mail. (e.g. there is an answering machine). Inspired by TYPE=msg parameter of the TEL property defined in RFC 2426 sec. 3.3.1" ; + rdfs:domain nco:VoicePhoneNumber ; + rdfs:label "voiceMail" ; + rdfs:range xsd:boolean ; + nrl:maxCardinality "1" . + + nco:PostalAddress + a rdfs:Class ; + rdfs:comment "A postal address. A class aggregating the various parts of a value for the 'ADR' property as defined in RFC 2426 Sec. 3.2.1." ; + rdfs:label "PostalAddress" ; + rdfs:subClassOf nco:ContactMedium . + + nco:belongsToGroup + a rdf:Property ; + rdfs:comment "Links a Contact with a ContactGroup it belongs to." ; + rdfs:domain nco:Contact ; + rdfs:label "belongsToGroup" ; + rdfs:range nco:ContactGroup . + + nco:hasContactMedium + a rdf:Property, nrl:DefiningProperty ; + rdfs:comment "A superProperty for all properties linking a Contact to an instance of a contact medium." ; + rdfs:domain nco:Role ; + rdfs:label "hasContactMedium" ; + rdfs:range nco:ContactMedium . + + nco:contactGroupName + a rdf:Property ; + rdfs:comment """The name of the contact group. This property was NOT defined + in the VCARD standard. See documentation of the 'ContactGroup' class for + details""" ; + rdfs:domain nco:ContactGroup ; + rdfs:label "contactGroupName" ; + rdfs:range xsd:string ; + rdfs:subPropertyOf dc:title ; + nrl:maxCardinality 1 . + + nco:FaxNumber + a rdfs:Class ; + rdfs:comment "A fax number. Inspired by the (TYPE=fax) parameter of the TEL property as defined in RFC 2426 sec 3.3.1." ; + rdfs:label "FaxNumber" ; + rdfs:subClassOf nco:PhoneNumber . + + nco:contactMediumComment + a rdf:Property ; + rdfs:comment "A comment about the contact medium. (Deprecated in favor of nie:comment or nao:description - based on the context)" ; + rdfs:domain nco:ContactMedium ; + rdfs:label "contactMediumComment" ; + rdfs:range xsd:string ; + nao:deprecated true. + + nco:foafUrl + a rdf:Property ; + rdfs:comment "The URL of the FOAF file." ; + rdfs:domain nco:Role ; + rdfs:label "foafUrl" ; + rdfs:range rdfs:Resource ; + rdfs:subPropertyOf nco:url . + + nco:CarPhoneNumber + a rdfs:Class ; + rdfs:comment "A car phone number. Inspired by the (TYPE=car) parameter of the TEL property as defined in RFC 2426 sec 3.3.1." ; + rdfs:label "CarPhoneNumber" ; + rdfs:subClassOf nco:VoicePhoneNumber . + + nco:ContactListDataObject + a rdfs:Class ; + rdfs:comment "An entity occuring on a contact list (usually interpreted as an nco:Contact)" ; + rdfs:label "ContactListDataObject" ; + rdfs:subClassOf nie:DataObject . + + nco:emailAddress + a rdf:Property ; + rdfs:domain nco:EmailAddress ; + rdfs:label "emailAddress" ; + rdfs:range xsd:string ; + nrl:maxCardinality 1 . + + nco:InternationalDeliveryAddress + a rdfs:Class ; + rdfs:comment "International Delivery Addresse. Class inspired by TYPE=intl parameter of the ADR property defined in RFC 2426 sec. 3.2.1" ; + rdfs:label "InternationalDeliveryAddress" ; + rdfs:subClassOf nco:PostalAddress . + + nco:locality + a rdf:Property ; + rdfs:comment "Locality or City. Inspired by the fourth part of the value of the 'ADR' property as defined in RFC 2426, sec. 3.2.1" ; + rdfs:domain nco:PostalAddress ; + rdfs:label "locality" ; + rdfs:range xsd:string ; + nrl:maxCardinality 1 . + + nco:VideoIMAccount + a rdfs:Class ; + nao:deprecated true ; + rdfs:comment "Deprecated in favour of nco:imCapabilityVideo." ; + rdfs:label "VideoIMAccount" ; + rdfs:subClassOf nco:AudioIMAccount . + + nco:sound + a rdf:Property ; + rdfs:comment "Sound clip attached to a Contact. The DataObject referred to by this property is usually interpreted as an nfo:Audio. Inspired by the SOUND property defined in RFC 2425 sec. 3.6.6." ; + rdfs:domain nco:Contact ; + rdfs:label "sound" ; + rdfs:range nie:DataObject ; + rdfs:subPropertyOf nie:hasPart . + + nco:EmailAddress + a rdfs:Class ; + rdfs:comment "An email address. The recommended best practice is to use mailto: uris for instances of this class." ; + rdfs:label "EmailAddress" ; + rdfs:subClassOf nco:ContactMedium . + + nco:imNickname + a rdf:Property ; + rdfs:comment "A nickname attached to a particular IM Account." ; + rdfs:domain nco:IMAccount ; + rdfs:label "imNickname" ; + rdfs:range xsd:string . + + nco:hobby + a rdf:Property ; + rdfs:comment "A hobby associated with a PersonContact. This property can be used to express hobbies and interests." ; + rdfs:domain nco:PersonContact ; + rdfs:label "hobby" ; + rdfs:range xsd:string . + + nco:blogUrl + a rdf:Property, nrl:DefiningProperty ; + rdfs:comment "A Blog url." ; + rdfs:domain nco:Role ; + rdfs:label "blogUrl" ; + rdfs:range rdfs:Resource ; + rdfs:subPropertyOf nco:url . + + nco:CellPhoneNumber + a rdfs:Class ; + rdfs:comment "A cellular phone number. Inspired by the (TYPE=cell) parameter of the TEL property as defined in RFC 2426 sec 3.3.1. Usually a cellular phone can accept voice calls as well as textual messages (SMS), therefore this class has two superclasses." ; + rdfs:label "CellPhoneNumber" ; + rdfs:subClassOf nco:MessagingNumber , nco:VoicePhoneNumber . + + nco:role + a rdf:Property ; + rdfs:comment "Role an object represented by this contact represents in the organization. This might include 'Programmer', 'Manager', 'Sales Representative'. Be careful to avoid confusion with the title property. An equivalent of the 'ROLE' property as defined in RFC 2426. Sec. 3.5.2. Note the difference between nco:Role class and nco:role property." ; + rdfs:domain nco:Affiliation ; + rdfs:label "role" ; + rdfs:range xsd:string . + + nco:DomesticDeliveryAddress + a rdfs:Class ; + rdfs:comment "Domestic Delivery Addresse. Class inspired by TYPE=dom parameter of the ADR property defined in RFC 2426 sec. 3.2.1" ; + rdfs:label "DomesticDeliveryAddress" ; + rdfs:subClassOf nco:PostalAddress . + + nco:female + a nco:Gender ; + rdfs:comment "A Female" ; + rdfs:label "female" . + + nco:hasPostalAddress + a rdf:Property ; + rdfs:comment "The default Address for a Contact. An equivalent of the 'ADR' property as defined in RFC 2426 Sec. 3.2.1." ; + rdfs:domain nco:Role ; + rdfs:label "hasPostalAddress" ; + rdfs:range nco:PostalAddress ; + rdfs:subPropertyOf nco:hasContactMedium . + + nco:imAccountType + a rdf:Property ; + rdfs:comment "Type of the IM account. This may be the name of the service that provides the IM functionality. Examples might include Jabber, ICQ, MSN etc" ; + rdfs:domain nco:IMAccount ; + rdfs:label "imAccountType" ; + rdfs:range xsd:string ; + nrl:maxCardinality "1" . + + nco:pobox + a rdf:Property ; + rdfs:comment "Post office box. This is the first part of the value of the 'ADR' property as defined in RFC 2426, sec. 3.2.1" ; + rdfs:domain nco:PostalAddress ; + rdfs:label "pobox" ; + rdfs:range xsd:string ; + nrl:maxCardinality "1". + + nco:hasAffiliation + a rdf:Property, nrl:DefiningProperty ; + rdfs:comment "Links a PersonContact with an Affiliation." ; + rdfs:domain nco:PersonContact ; + rdfs:label "hasAffiliation" ; + rdfs:range nco:Affiliation . + + nco:gender + a rdf:Property ; + rdfs:comment "Gender of the given contact." ; + rdfs:domain nco:PersonContact ; + rdfs:label "gender" ; + rdfs:range nco:Gender ; + nrl:maxCardinality 1 . + + nco:imStatusMessage + a rdf:Property, nrl:NonDefiningProperty ; + rdfs:comment "A feature common in most IM systems. A message left by the user for all his/her contacts to see." ; + rdfs:domain nco:IMAccount ; + rdfs:label "imStatusMessage" ; + rdfs:range xsd:string ; + nrl:maxCardinality "1" . + + nco:start + a rdf:Property ; + rdfs:comment "Start datetime for the role, such as: the datetime of joining a project or organization, datetime of starting employment, datetime of marriage" ; + rdfs:label "start" ; + rdfs:domain nco:Role ; + rdfs:range xsd:dateTime ; + nrl:maxCardinality 1 . + + nco:end + a rdf:Property; + rdfs:comment "End datetime for the role, such as: the datetime of leaving a project or organization, datetime of ending employment, datetime of divorce. If absent or set to a date in the future, the role is currently active." ; + rdfs:label "end" ; + rdfs:domain nco:Role ; + rdfs:range xsd:dateTime ; + nrl:maxCardinality 1 . + + nco:IMCapability a rdfs:Class ; + rdfs:label "imCapability" ; + rdfs:comment "Capabilities of a cetain IMAccount." ; + rdfs:subClassOf rdfs:Resource . + + nco:imCapabilityText a nco:IMCapability . + nco:imCapabilityAudio a nco:IMCapability . + nco:imCapabilityVideo a nco:IMCapability . + + nco:hasIMCapability + a rdf:Property, nrl:DefiningProperty ; + rdfs:comment "Indicates that an IMAccount has a certain capability." ; + rdfs:domain nco:IMAccount ; + rdfs:label "hasIMCapability" ; + rdfs:range nco:IMCapability . + + nco:isAccessedBy + a rdf:Property ; + rdfs:comment "Indicates the local IMAccount by which this IMAccount is accessed. This does not imply membership of a contact list." ; + rdfs:label "isKnownBy" ; + rdfs:domain nco:IMAccount ; + rdfs:range nco:IMAccount . + + nco:publishesPresenceTo + a rdf:Property ; + rdfs:comment "Indicates that this IMAccount publishes its presence information to the other IMAccount." ; + rdfs:label "publishesPresenceTo" ; + rdfs:domain nco:IMAccount ; + rdfs:range nco:IMAccount . + + nco:requestedPresenceSubscriptionTo + a rdf:Property ; + rdfs:comment "Indicates that this IMAccount has requested a subscription to the presence information of the other IMAccount." ; + rdfs:label "requestedPresenceSubscriptionTo" ; + rdfs:domain nco:IMAccount ; + rdfs:range nco:IMAccount . + + nco:isBlocked + a rdf:Property ; + rdfs:comment "Indicates that this IMAccount has been blocked." ; + rdfs:domain nco:IMAccount ; + rdfs:label "isBlocked" ; + rdfs:range xsd:boolean ; + nrl:maxCardinality "1" . +} + + {nco: a nrl:Ontology ; + nao:creator ; + nao:hasDefaultNamespace + "http://www.semanticdesktop.org/ontologies/2007/03/22/nco#" ; + nao:hasDefaultNamespaceAbbreviation + "nco" ; + nao:lastModified "2011-12-13T12:44:58Z" ; + nao:status "Unstable" ; + nao:updatable "0 " ; + nao:version "0.10.0" ; + nao:prefLabel "Nepomuk Contact Ontology" ; + nao:description "The Nepomuk Contact Ontology describes contact information, common in many places on the desktop. It evolved from the VCARD specification (RFC 2426) and has been inspired by the Vcard Ontology by Renato Ianella. The scope of NCO is much broader though." . + + + a nrl:GraphMetadata ; + nrl:coreGraphMetadataFor + nco: . +} diff --git a/tests/Trinity.Tests.Fuseki/ontologies/owl.n3 b/tests/Trinity.Tests.Fuseki/ontologies/owl.n3 new file mode 100644 index 00000000..87467e7d --- /dev/null +++ b/tests/Trinity.Tests.Fuseki/ontologies/owl.n3 @@ -0,0 +1,552 @@ +@prefix dc: . +@prefix grddl: . +@prefix owl: . +@prefix rdf: . +@prefix rdfs: . +@prefix xml: . +@prefix xsd: . + + a owl:Ontology ; + dc:title "The OWL 2 Schema vocabulary (OWL 2)" ; + rdfs:comment """ + This ontology partially describes the built-in classes and + properties that together form the basis of the RDF/XML syntax of OWL 2. + The content of this ontology is based on Tables 6.1 and 6.2 + in Section 6.4 of the OWL 2 RDF-Based Semantics specification, + available at http://www.w3.org/TR/owl2-rdf-based-semantics/. + Please note that those tables do not include the different annotations + (labels, comments and rdfs:isDefinedBy links) used in this file. + Also note that the descriptions provided in this ontology do not + provide a complete and correct formal description of either the syntax + or the semantics of the introduced terms (please see the OWL 2 + recommendations for the complete and normative specifications). + Furthermore, the information provided by this ontology may be + misleading if not used with care. This ontology SHOULD NOT be imported + into OWL ontologies. Importing this file into an OWL 2 DL ontology + will cause it to become an OWL 2 Full ontology and may have other, + unexpected, consequences. + """ ; + rdfs:isDefinedBy + , + , + ; + rdfs:seeAlso , + ; + owl:imports ; + owl:versionIRI ; + owl:versionInfo "$Date: 2009/11/15 10:54:12 $" ; + grddl:namespaceTransformation . + + +owl:AllDifferent a rdfs:Class ; + rdfs:label "AllDifferent" ; + rdfs:comment "The class of collections of pairwise different individuals." ; + rdfs:isDefinedBy ; + rdfs:subClassOf rdfs:Resource . + +owl:AllDisjointClasses a rdfs:Class ; + rdfs:label "AllDisjointClasses" ; + rdfs:comment "The class of collections of pairwise disjoint classes." ; + rdfs:isDefinedBy ; + rdfs:subClassOf rdfs:Resource . + +owl:AllDisjointProperties a rdfs:Class ; + rdfs:label "AllDisjointProperties" ; + rdfs:comment "The class of collections of pairwise disjoint properties." ; + rdfs:isDefinedBy ; + rdfs:subClassOf rdfs:Resource . + +owl:Annotation a rdfs:Class ; + rdfs:label "Annotation" ; + rdfs:comment "The class of annotated annotations for which the RDF serialization consists of an annotated subject, predicate and object." ; + rdfs:isDefinedBy ; + rdfs:subClassOf rdfs:Resource . + +owl:AnnotationProperty a rdfs:Class ; + rdfs:label "AnnotationProperty" ; + rdfs:comment "The class of annotation properties." ; + rdfs:isDefinedBy ; + rdfs:subClassOf rdf:Property . + +owl:AsymmetricProperty a rdfs:Class ; + rdfs:label "AsymmetricProperty" ; + rdfs:comment "The class of asymmetric properties." ; + rdfs:isDefinedBy ; + rdfs:subClassOf owl:ObjectProperty . + +owl:Axiom a rdfs:Class ; + rdfs:label "Axiom" ; + rdfs:comment "The class of annotated axioms for which the RDF serialization consists of an annotated subject, predicate and object." ; + rdfs:isDefinedBy ; + rdfs:subClassOf rdfs:Resource . + +owl:Class a rdfs:Class ; + rdfs:label "Class" ; + rdfs:comment "The class of OWL classes." ; + rdfs:isDefinedBy ; + rdfs:subClassOf rdfs:Class . + +owl:DataRange a rdfs:Class ; + rdfs:label "DataRange" ; + rdfs:comment "The class of OWL data ranges, which are special kinds of datatypes. Note: The use of the IRI owl:DataRange has been deprecated as of OWL 2. The IRI rdfs:Datatype SHOULD be used instead." ; + rdfs:isDefinedBy ; + rdfs:subClassOf rdfs:Datatype . + +owl:DatatypeProperty a rdfs:Class ; + rdfs:label "DatatypeProperty" ; + rdfs:comment "The class of data properties." ; + rdfs:isDefinedBy ; + rdfs:subClassOf rdf:Property . + +owl:DeprecatedClass a rdfs:Class ; + rdfs:label "DeprecatedClass" ; + rdfs:comment "The class of deprecated classes." ; + rdfs:isDefinedBy ; + rdfs:subClassOf rdfs:Class . + +owl:DeprecatedProperty a rdfs:Class ; + rdfs:label "DeprecatedProperty" ; + rdfs:comment "The class of deprecated properties." ; + rdfs:isDefinedBy ; + rdfs:subClassOf rdf:Property . + +owl:FunctionalProperty a rdfs:Class ; + rdfs:label "FunctionalProperty" ; + rdfs:comment "The class of functional properties." ; + rdfs:isDefinedBy ; + rdfs:subClassOf rdf:Property . + +owl:InverseFunctionalProperty a rdfs:Class ; + rdfs:label "InverseFunctionalProperty" ; + rdfs:comment "The class of inverse-functional properties." ; + rdfs:isDefinedBy ; + rdfs:subClassOf owl:ObjectProperty . + +owl:IrreflexiveProperty a rdfs:Class ; + rdfs:label "IrreflexiveProperty" ; + rdfs:comment "The class of irreflexive properties." ; + rdfs:isDefinedBy ; + rdfs:subClassOf owl:ObjectProperty . + +owl:NamedIndividual a rdfs:Class ; + rdfs:label "NamedIndividual" ; + rdfs:comment "The class of named individuals." ; + rdfs:isDefinedBy ; + rdfs:subClassOf owl:Thing . + +owl:NegativePropertyAssertion a rdfs:Class ; + rdfs:label "NegativePropertyAssertion" ; + rdfs:comment "The class of negative property assertions." ; + rdfs:isDefinedBy ; + rdfs:subClassOf rdfs:Resource . + +owl:Nothing a owl:Class ; + rdfs:label "Nothing" ; + rdfs:comment "This is the empty class." ; + rdfs:isDefinedBy ; + rdfs:subClassOf owl:Thing . + +owl:ObjectProperty a rdfs:Class ; + rdfs:label "ObjectProperty" ; + rdfs:comment "The class of object properties." ; + rdfs:isDefinedBy ; + rdfs:subClassOf rdf:Property . + +owl:Ontology a rdfs:Class ; + rdfs:label "Ontology" ; + rdfs:comment "The class of ontologies." ; + rdfs:isDefinedBy ; + rdfs:subClassOf rdfs:Resource . + +owl:OntologyProperty a rdfs:Class ; + rdfs:label "OntologyProperty" ; + rdfs:comment "The class of ontology properties." ; + rdfs:isDefinedBy ; + rdfs:subClassOf rdf:Property . + +owl:ReflexiveProperty a rdfs:Class ; + rdfs:label "ReflexiveProperty" ; + rdfs:comment "The class of reflexive properties." ; + rdfs:isDefinedBy ; + rdfs:subClassOf owl:ObjectProperty . + +owl:Restriction a rdfs:Class ; + rdfs:label "Restriction" ; + rdfs:comment "The class of property restrictions." ; + rdfs:isDefinedBy ; + rdfs:subClassOf owl:Class . + +owl:SymmetricProperty a rdfs:Class ; + rdfs:label "SymmetricProperty" ; + rdfs:comment "The class of symmetric properties." ; + rdfs:isDefinedBy ; + rdfs:subClassOf owl:ObjectProperty . + +owl:TransitiveProperty a rdfs:Class ; + rdfs:label "TransitiveProperty" ; + rdfs:comment "The class of transitive properties." ; + rdfs:isDefinedBy ; + rdfs:subClassOf owl:ObjectProperty . + +owl:Thing a owl:Class ; + rdfs:label "Thing" ; + rdfs:comment "The class of OWL individuals." ; + rdfs:isDefinedBy . + +owl:allValuesFrom a rdf:Property ; + rdfs:label "allValuesFrom" ; + rdfs:comment "The property that determines the class that a universal property restriction refers to." ; + rdfs:domain owl:Restriction ; + rdfs:isDefinedBy ; + rdfs:range rdfs:Class . + +owl:annotatedProperty a rdf:Property ; + rdfs:label "annotatedProperty" ; + rdfs:comment "The property that determines the predicate of an annotated axiom or annotated annotation." ; + rdfs:domain rdfs:Resource ; + rdfs:isDefinedBy ; + rdfs:range rdfs:Resource . + +owl:annotatedSource a rdf:Property ; + rdfs:label "annotatedSource" ; + rdfs:comment "The property that determines the subject of an annotated axiom or annotated annotation." ; + rdfs:domain rdfs:Resource ; + rdfs:isDefinedBy ; + rdfs:range rdfs:Resource . + +owl:annotatedTarget a rdf:Property ; + rdfs:label "annotatedTarget" ; + rdfs:comment "The property that determines the object of an annotated axiom or annotated annotation." ; + rdfs:domain rdfs:Resource ; + rdfs:isDefinedBy ; + rdfs:range rdfs:Resource . + +owl:assertionProperty a rdf:Property ; + rdfs:label "assertionProperty" ; + rdfs:comment "The property that determines the predicate of a negative property assertion." ; + rdfs:domain owl:NegativePropertyAssertion ; + rdfs:isDefinedBy ; + rdfs:range rdf:Property . + +owl:backwardCompatibleWith a owl:AnnotationProperty, owl:OntologyProperty ; + rdfs:label "backwardCompatibleWith" ; + rdfs:comment "The annotation property that indicates that a given ontology is backward compatible with another ontology." ; + rdfs:domain owl:Ontology ; + rdfs:isDefinedBy ; + rdfs:range owl:Ontology . + +owl:bottomDataProperty a owl:DatatypeProperty ; + rdfs:label "bottomDataProperty" ; + rdfs:comment "The data property that does not relate any individual to any data value." ; + rdfs:domain owl:Thing ; + rdfs:isDefinedBy ; + rdfs:range rdfs:Literal . + +owl:bottomObjectProperty a owl:ObjectProperty ; + rdfs:label "bottomObjectProperty" ; + rdfs:comment "The object property that does not relate any two individuals." ; + rdfs:domain owl:Thing ; + rdfs:isDefinedBy ; + rdfs:range owl:Thing . + +owl:cardinality a rdf:Property ; + rdfs:label "cardinality" ; + rdfs:comment "The property that determines the cardinality of an exact cardinality restriction." ; + rdfs:domain owl:Restriction ; + rdfs:isDefinedBy ; + rdfs:range xsd:nonNegativeInteger . + +owl:complementOf a rdf:Property ; + rdfs:label "complementOf" ; + rdfs:comment "The property that determines that a given class is the complement of another class." ; + rdfs:domain owl:Class ; + rdfs:isDefinedBy ; + rdfs:range owl:Class . + +owl:datatypeComplementOf a rdf:Property ; + rdfs:label "datatypeComplementOf" ; + rdfs:comment "The property that determines that a given data range is the complement of another data range with respect to the data domain." ; + rdfs:domain rdfs:Datatype ; + rdfs:isDefinedBy ; + rdfs:range rdfs:Datatype . + +owl:deprecated a owl:AnnotationProperty ; + rdfs:label "deprecated" ; + rdfs:comment "The annotation property that indicates that a given entity has been deprecated." ; + rdfs:domain rdfs:Resource ; + rdfs:isDefinedBy ; + rdfs:range rdfs:Resource . + +owl:differentFrom a rdf:Property ; + rdfs:label "differentFrom" ; + rdfs:comment "The property that determines that two given individuals are different." ; + rdfs:domain owl:Thing ; + rdfs:isDefinedBy ; + rdfs:range owl:Thing . + +owl:disjointUnionOf a rdf:Property ; + rdfs:label "disjointUnionOf" ; + rdfs:comment "The property that determines that a given class is equivalent to the disjoint union of a collection of other classes." ; + rdfs:domain owl:Class ; + rdfs:isDefinedBy ; + rdfs:range rdf:List . + +owl:disjointWith a rdf:Property ; + rdfs:label "disjointWith" ; + rdfs:comment "The property that determines that two given classes are disjoint." ; + rdfs:domain owl:Class ; + rdfs:isDefinedBy ; + rdfs:range owl:Class . + +owl:distinctMembers a rdf:Property ; + rdfs:label "distinctMembers" ; + rdfs:comment "The property that determines the collection of pairwise different individuals in a owl:AllDifferent axiom." ; + rdfs:domain owl:AllDifferent ; + rdfs:isDefinedBy ; + rdfs:range rdf:List . + +owl:equivalentClass a rdf:Property ; + rdfs:label "equivalentClass" ; + rdfs:comment "The property that determines that two given classes are equivalent, and that is used to specify datatype definitions." ; + rdfs:domain rdfs:Class ; + rdfs:isDefinedBy ; + rdfs:range rdfs:Class . + +owl:equivalentProperty a rdf:Property ; + rdfs:label "equivalentProperty" ; + rdfs:comment "The property that determines that two given properties are equivalent." ; + rdfs:domain rdf:Property ; + rdfs:isDefinedBy ; + rdfs:range rdf:Property . + +owl:hasKey a rdf:Property ; + rdfs:label "hasKey" ; + rdfs:comment "The property that determines the collection of properties that jointly build a key." ; + rdfs:domain owl:Class ; + rdfs:isDefinedBy ; + rdfs:range rdf:List . + +owl:hasSelf a rdf:Property ; + rdfs:label "hasSelf" ; + rdfs:comment "The property that determines the property that a self restriction refers to." ; + rdfs:domain owl:Restriction ; + rdfs:isDefinedBy ; + rdfs:range rdfs:Resource . + +owl:hasValue a rdf:Property ; + rdfs:label "hasValue" ; + rdfs:comment "The property that determines the individual that a has-value restriction refers to." ; + rdfs:domain owl:Restriction ; + rdfs:isDefinedBy ; + rdfs:range rdfs:Resource . + +owl:imports a owl:OntologyProperty ; + rdfs:label "imports" ; + rdfs:comment "The property that is used for importing other ontologies into a given ontology." ; + rdfs:domain owl:Ontology ; + rdfs:isDefinedBy ; + rdfs:range owl:Ontology . + +owl:incompatibleWith a owl:AnnotationProperty, owl:OntologyProperty ; + rdfs:label "incompatibleWith" ; + rdfs:comment "The annotation property that indicates that a given ontology is incompatible with another ontology." ; + rdfs:domain owl:Ontology ; + rdfs:isDefinedBy ; + rdfs:range owl:Ontology . + +owl:intersectionOf a rdf:Property ; + rdfs:label "intersectionOf" ; + rdfs:comment "The property that determines the collection of classes or data ranges that build an intersection." ; + rdfs:domain rdfs:Class ; + rdfs:isDefinedBy ; + rdfs:range rdf:List . + +owl:inverseOf a rdf:Property ; + rdfs:label "inverseOf" ; + rdfs:comment "The property that determines that two given properties are inverse." ; + rdfs:domain owl:ObjectProperty ; + rdfs:isDefinedBy ; + rdfs:range owl:ObjectProperty . + +owl:maxCardinality a rdf:Property ; + rdfs:label "maxCardinality" ; + rdfs:comment "The property that determines the cardinality of a maximum cardinality restriction." ; + rdfs:domain owl:Restriction ; + rdfs:isDefinedBy ; + rdfs:range xsd:nonNegativeInteger . + +owl:maxQualifiedCardinality a rdf:Property ; + rdfs:label "maxQualifiedCardinality" ; + rdfs:comment "The property that determines the cardinality of a maximum qualified cardinality restriction." ; + rdfs:domain owl:Restriction ; + rdfs:isDefinedBy ; + rdfs:range xsd:nonNegativeInteger . + +owl:members a rdf:Property ; + rdfs:label "members" ; + rdfs:comment "The property that determines the collection of members in either a owl:AllDifferent, owl:AllDisjointClasses or owl:AllDisjointProperties axiom." ; + rdfs:domain rdfs:Resource ; + rdfs:isDefinedBy ; + rdfs:range rdf:List . + +owl:minCardinality a rdf:Property ; + rdfs:label "minCardinality" ; + rdfs:comment "The property that determines the cardinality of a minimum cardinality restriction." ; + rdfs:domain owl:Restriction ; + rdfs:isDefinedBy ; + rdfs:range xsd:nonNegativeInteger . + +owl:minQualifiedCardinality a rdf:Property ; + rdfs:label "minQualifiedCardinality" ; + rdfs:comment "The property that determines the cardinality of a minimum qualified cardinality restriction." ; + rdfs:domain owl:Restriction ; + rdfs:isDefinedBy ; + rdfs:range xsd:nonNegativeInteger . + +owl:onClass a rdf:Property ; + rdfs:label "onClass" ; + rdfs:comment "The property that determines the class that a qualified object cardinality restriction refers to." ; + rdfs:domain owl:Restriction ; + rdfs:isDefinedBy ; + rdfs:range owl:Class . + +owl:onDataRange a rdf:Property ; + rdfs:label "onDataRange" ; + rdfs:comment "The property that determines the data range that a qualified data cardinality restriction refers to." ; + rdfs:domain owl:Restriction ; + rdfs:isDefinedBy ; + rdfs:range rdfs:Datatype . + +owl:onDatatype a rdf:Property ; + rdfs:label "onDatatype" ; + rdfs:comment "The property that determines the datatype that a datatype restriction refers to." ; + rdfs:domain rdfs:Datatype ; + rdfs:isDefinedBy ; + rdfs:range rdfs:Datatype . + +owl:oneOf a rdf:Property ; + rdfs:label "oneOf" ; + rdfs:comment "The property that determines the collection of individuals or data values that build an enumeration." ; + rdfs:domain rdfs:Class ; + rdfs:isDefinedBy ; + rdfs:range rdf:List . + +owl:onProperties a rdf:Property ; + rdfs:label "onProperties" ; + rdfs:comment "The property that determines the n-tuple of properties that a property restriction on an n-ary data range refers to." ; + rdfs:domain owl:Restriction ; + rdfs:isDefinedBy ; + rdfs:range rdf:List . + +owl:onProperty a rdf:Property ; + rdfs:label "onProperty" ; + rdfs:comment "The property that determines the property that a property restriction refers to." ; + rdfs:domain owl:Restriction ; + rdfs:isDefinedBy ; + rdfs:range rdf:Property . + +owl:priorVersion a owl:AnnotationProperty, owl:OntologyProperty ; + rdfs:label "priorVersion" ; + rdfs:comment "The annotation property that indicates the predecessor ontology of a given ontology." ; + rdfs:domain owl:Ontology ; + rdfs:isDefinedBy ; + rdfs:range owl:Ontology . + +owl:propertyChainAxiom a rdf:Property ; + rdfs:label "propertyChainAxiom" ; + rdfs:comment "The property that determines the n-tuple of properties that build a sub property chain of a given property." ; + rdfs:domain owl:ObjectProperty ; + rdfs:isDefinedBy ; + rdfs:range rdf:List . + +owl:propertyDisjointWith a rdf:Property ; + rdfs:label "propertyDisjointWith" ; + rdfs:comment "The property that determines that two given properties are disjoint." ; + rdfs:domain rdf:Property ; + rdfs:isDefinedBy ; + rdfs:range rdf:Property . + +owl:qualifiedCardinality a rdf:Property ; + rdfs:label "qualifiedCardinality" ; + rdfs:comment "The property that determines the cardinality of an exact qualified cardinality restriction." ; + rdfs:domain owl:Restriction ; + rdfs:isDefinedBy ; + rdfs:range xsd:nonNegativeInteger . + +owl:sameAs a rdf:Property ; + rdfs:label "sameAs" ; + rdfs:comment "The property that determines that two given individuals are equal." ; + rdfs:domain owl:Thing ; + rdfs:isDefinedBy ; + rdfs:range owl:Thing . + +owl:someValuesFrom a rdf:Property ; + rdfs:label "someValuesFrom" ; + rdfs:comment "The property that determines the class that an existential property restriction refers to." ; + rdfs:domain owl:Restriction ; + rdfs:isDefinedBy ; + rdfs:range rdfs:Class . + +owl:sourceIndividual a rdf:Property ; + rdfs:label "sourceIndividual" ; + rdfs:comment "The property that determines the subject of a negative property assertion." ; + rdfs:domain owl:NegativePropertyAssertion ; + rdfs:isDefinedBy ; + rdfs:range owl:Thing . + +owl:targetIndividual a rdf:Property ; + rdfs:label "targetIndividual" ; + rdfs:comment "The property that determines the object of a negative object property assertion." ; + rdfs:domain owl:NegativePropertyAssertion ; + rdfs:isDefinedBy ; + rdfs:range owl:Thing . + +owl:targetValue a rdf:Property ; + rdfs:label "targetValue" ; + rdfs:comment "The property that determines the value of a negative data property assertion." ; + rdfs:domain owl:NegativePropertyAssertion ; + rdfs:isDefinedBy ; + rdfs:range rdfs:Literal . + +owl:topDataProperty a owl:DatatypeProperty ; + rdfs:label "topDataProperty" ; + rdfs:comment "The data property that relates every individual to every data value." ; + rdfs:domain owl:Thing ; + rdfs:isDefinedBy ; + rdfs:range rdfs:Literal . + +owl:topObjectProperty a owl:ObjectProperty ; + rdfs:label "topObjectProperty" ; + rdfs:comment "The object property that relates every two individuals." ; + rdfs:domain owl:Thing ; + rdfs:isDefinedBy ; + rdfs:range owl:Thing . + +owl:unionOf a rdf:Property ; + rdfs:label "unionOf" ; + rdfs:comment "The property that determines the collection of classes or data ranges that build a union." ; + rdfs:domain rdfs:Class ; + rdfs:isDefinedBy ; + rdfs:range rdf:List . + +owl:versionInfo a owl:AnnotationProperty ; + rdfs:label "versionInfo" ; + rdfs:comment "The annotation property that provides version information for an ontology or another OWL construct." ; + rdfs:domain rdfs:Resource ; + rdfs:isDefinedBy ; + rdfs:range rdfs:Resource . + +owl:versionIRI a owl:OntologyProperty ; + rdfs:label "versionIRI" ; + rdfs:comment "The property that identifies the version IRI of an ontology." ; + rdfs:domain owl:Ontology ; + rdfs:isDefinedBy ; + rdfs:range owl:Ontology . + +owl:withRestrictions a rdf:Property ; + rdfs:label "withRestrictions" ; + rdfs:comment "The property that determines the collection of facet-value pairs that define a datatype restriction." ; + rdfs:domain rdfs:Datatype ; + rdfs:isDefinedBy ; + rdfs:range rdf:List . + \ No newline at end of file diff --git a/tests/Trinity.Tests.Fuseki/ontologies/rdf.rdf b/tests/Trinity.Tests.Fuseki/ontologies/rdf.rdf new file mode 100644 index 00000000..a6815ecc --- /dev/null +++ b/tests/Trinity.Tests.Fuseki/ontologies/rdf.rdf @@ -0,0 +1,156 @@ + + + + The RDF Concepts Vocabulary (RDF) + This is the RDF Schema for the RDF vocabulary terms in the RDF Namespace, defined in RDF 1.1 Concepts. + + + + + + + HTML + The datatype of RDF literals storing fragments of HTML content + + + + + + + langString + The datatype of language-tagged string values + + + + + + + PlainLiteral + The class of plain (i.e. untyped) literal values, as used in RIF and OWL 2 + + + + + + type + The subject is an instance of a class. + + + + + + + Property + The class of RDF properties. + + + + + + Statement + + The class of RDF statements. + + + + + subject + The subject of the subject RDF statement. + + + + + + + predicate + The predicate of the subject RDF statement. + + + + + + + object + The object of the subject RDF statement. + + + + + + + Bag + The class of unordered containers. + + + + + + Seq + The class of ordered containers. + + + + + + Alt + The class of containers of alternatives. + + + + + + value + Idiomatic property used for structured values. + + + + + + + + + List + The class of RDF Lists. + + + + + + nil + The empty list, with no items in it. If the rest of a list is nil then the list has no more items in it. + + + + + first + The first item in the subject RDF list. + + + + + + + rest + The rest of the subject RDF list after the first item. + + + + + + + + XMLLiteral + The datatype of XML literal values. + + + + + + + + diff --git a/tests/Trinity.Tests.Fuseki/ontologies/rdfs.n3 b/tests/Trinity.Tests.Fuseki/ontologies/rdfs.n3 new file mode 100644 index 00000000..a5b8eac6 --- /dev/null +++ b/tests/Trinity.Tests.Fuseki/ontologies/rdfs.n3 @@ -0,0 +1,109 @@ +@prefix rdf: . +@prefix rdfs: . +@prefix owl: . +@prefix dc: . + + a owl:Ontology ; + dc:title "The RDF Schema vocabulary (RDFS)" . + +rdfs:Resource a rdfs:Class ; + rdfs:isDefinedBy ; + rdfs:label "Resource" ; + rdfs:comment "The class resource, everything." . + +rdfs:Class a rdfs:Class ; + rdfs:isDefinedBy ; + rdfs:label "Class" ; + rdfs:comment "The class of classes." ; + rdfs:subClassOf rdfs:Resource . + +rdfs:subClassOf a rdf:Property ; + rdfs:isDefinedBy ; + rdfs:label "subClassOf" ; + rdfs:comment "The subject is a subclass of a class." ; + rdfs:range rdfs:Class ; + rdfs:domain rdfs:Class . + +rdfs:subPropertyOf a rdf:Property ; + rdfs:isDefinedBy ; + rdfs:label "subPropertyOf" ; + rdfs:comment "The subject is a subproperty of a property." ; + rdfs:range rdf:Property ; + rdfs:domain rdf:Property . + +rdfs:comment a rdf:Property ; + rdfs:isDefinedBy ; + rdfs:label "comment" ; + rdfs:comment "A description of the subject resource." ; + rdfs:domain rdfs:Resource ; + rdfs:range rdfs:Literal . + +rdfs:label a rdf:Property ; + rdfs:isDefinedBy ; + rdfs:label "label" ; + rdfs:comment "A human-readable name for the subject." ; + rdfs:domain rdfs:Resource ; + rdfs:range rdfs:Literal . + +rdfs:domain a rdf:Property ; + rdfs:isDefinedBy ; + rdfs:label "domain" ; + rdfs:comment "A domain of the subject property." ; + rdfs:range rdfs:Class ; + rdfs:domain rdf:Property . + +rdfs:range a rdf:Property ; + rdfs:isDefinedBy ; + rdfs:label "range" ; + rdfs:comment "A range of the subject property." ; + rdfs:range rdfs:Class ; + rdfs:domain rdf:Property . + +rdfs:seeAlso a rdf:Property ; + rdfs:isDefinedBy ; + rdfs:label "seeAlso" ; + rdfs:comment "Further information about the subject resource." ; + rdfs:range rdfs:Resource ; + rdfs:domain rdfs:Resource . + +rdfs:isDefinedBy a rdf:Property ; + rdfs:isDefinedBy ; + rdfs:subPropertyOf rdfs:seeAlso ; + rdfs:label "isDefinedBy" ; + rdfs:comment "The defininition of the subject resource." ; + rdfs:range rdfs:Resource ; + rdfs:domain rdfs:Resource . + +rdfs:Literal a rdfs:Class ; + rdfs:isDefinedBy ; + rdfs:label "Literal" ; + rdfs:comment "The class of literal values, eg. textual strings and integers." ; + rdfs:subClassOf rdfs:Resource . + +rdfs:Container a rdfs:Class ; + rdfs:isDefinedBy ; + rdfs:label "Container" ; + rdfs:subClassOf rdfs:Resource ; + rdfs:comment "The class of RDF containers." . + +rdfs:ContainerMembershipProperty a rdfs:Class ; + rdfs:isDefinedBy ; + rdfs:label "ContainerMembershipProperty" ; + rdfs:comment """The class of container membership properties, rdf:_1, rdf:_2, ..., + all of which are sub-properties of 'member'.""" ; + rdfs:subClassOf rdf:Property . + +rdfs:member a rdf:Property ; + rdfs:isDefinedBy ; + rdfs:label "member" ; + rdfs:comment "A member of the subject resource." ; + rdfs:domain rdfs:Resource ; + rdfs:range rdfs:Resource . + +rdfs:Datatype a rdfs:Class ; + rdfs:isDefinedBy ; + rdfs:label "Datatype" ; + rdfs:comment "The class of RDF datatypes." ; + rdfs:subClassOf rdfs:Class . + + rdfs:seeAlso .