/// <summary> /// Applies inference to the Input Graph and outputs the inferred information to the Output Graph. /// </summary> /// <param name="input">Graph to apply inference to.</param> /// <param name="output">Graph inferred information is output to.</param> public virtual void Apply(IGraph input, IGraph output) { // Infer information List <Triple> inferences = new List <Triple>(); foreach (Triple t in input.Triples) { // Apply class/property hierarchy inferencing if (t.Predicate.Equals(_rdfType)) { if (!t.Object.Equals(_rdfsClass) && !t.Object.Equals(_rdfProperty)) { InferClasses(t, input, output, inferences); } } else if (t.Predicate.Equals(_rdfsSubClass)) { // Assert that this thing is a Class inferences.Add(new Triple(t.Subject.CopyNode(output), _rdfType.CopyNode(output), _rdfsClass.CopyNode(output))); } else if (t.Predicate.Equals(_rdfsSubProperty)) { // Assert that this thing is a Property inferences.Add(new Triple(t.Subject.CopyNode(output), _rdfType.CopyNode(output), _rdfProperty.CopyNode(output))); } else if (_propertyMappings.ContainsKey(t.Predicate)) { INode property = t.Predicate; // Navigate up the property hierarchy asserting additional properties if able while (_propertyMappings.ContainsKey(property)) { if (_propertyMappings[property] != null) { // Assert additional properties inferences.Add(new Triple(t.Subject.CopyNode(output), _propertyMappings[property].CopyNode(output), t.Object.CopyNode(output))); property = _propertyMappings[property]; } else { break; } } } } // Assert the inferred information inferences.RemoveAll(t => t.Subject.NodeType == NodeType.Literal); if (inferences.Count > 0) { output.Assert(inferences); } }
private static INode Clone(this INode node, IGraph targetGraph, Uri currentId, Uri newId) { if (!(node is IUriNode)) { return(node.CopyNode(targetGraph)); } IUriNode uriNode = (IUriNode)node; return(AbsoluteUriComparer.Default.Equals(uriNode.Uri, currentId) ? targetGraph.CreateUriNode(newId) : uriNode.CopyNode(targetGraph)); }