Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Generate New Relationships With RDFS+ Inferencing in AnzoGraph

DZone 's Guide to

How to Generate New Relationships With RDFS+ Inferencing in AnzoGraph

This article explains how to generate inferences with AnzoGraph and describes the supported inference vocabularies.

· Database Zone ·
Free Resource

AnzoGraph includes an RDFS+ inference engine that can create new relationships based on the vocabularies or ontologies in the existing data.

The following example from the W3C Semantic Web Inference documentation illustrates the inference concept:

A data set might include the relationship "Flipper isA Dolphin." An ontology might declare that "every Dolphin is also a Mammal." An inference program that understands the notion of "X is also Y" adds the statement "Flipper isA Mammal" to the set of relationships even though it was not specified in the original data.

When AnzoGraph creates inferences, it scans the specified graph for any of the supported RDFS and OWL ontologies and generates new triples according to the W3C OWL 2 RL rules.

This article explains how to generate inferences with AnzoGraph and describes the supported inference vocabularies. You can download a free trial of AnzoGraph and try the inference example that follows.

Generating Inferences With AnzoGraph

In AnzoGraph, run the following command to generate inferences from an existing graph:

 CREATE INFERENCES [ FROM source_graph ] INTO GRAPH target_graph 

When you run the CREATE INFERENCES command, AnzoGraph runs rules for each of the following RDFS and OWL ontologies that it finds and inserts the inferred triples into the specified target graph:

  • owl:equivalentClass: Indicates that two classes are synonymous.
  • owl:equivalentProperty: Indicates that two properties are synonymous.
  • owl:intersectionOf: Indicates that an instance belongs to every one of the specified classes.
  • owl:inverseOf: Indicates that two properties are the inverse of each other.
  • owl:sameAs: Indicates that two instances are equal and have the same meaning. All statements about one instance are true for the other instance.
  • owl:someValuesFrom: Indicates that at least one object of a property is a member of the specified class.
  • owl:SymmetricProperty: Indicates that the inverse is true for a property. If a property relates A to B then it also relates B to A.
  • owl:TransitiveProperty: Indicates that chains of relationships collapse into a single relationship. If property A links to B and B links to C, then A links to C.
  • rdfs:domain: Indicates that the subject of a triple is classified into the domain of the predicate.
  • rdfs:range: Indicates that the object of the triple is classified into the range of the predicate.
  • rdfs:subClassOf: Indicates that members of a subclass are also members of the superclass.
  • rdfs:subPropertyOf: Indicates that relationships that are described by a subproperty also hold for the superproperty.

Inference Example

The following simple example demonstrates the inferences that AnzoGraph generates to infer friendships from a sample "Friends" data set below. The example Turtle file loads data about people, including a person’s name, a list of their likes and dislikes, and their friends. In the file, the friend relationship is described as an owl:TransitiveProperty type (<friend> a owl:TransitiveProperty):

# friends.ttl
PREFIX owl: <http://www.w3.org/2002/07/owl#> .
<friend> a owl:TransitiveProperty .
<person1>
rdf:type <person>
;<name> "Rafael Taylor"
;<like> "sports","theatre","classical","vegas","musicals"
;<dislike> "jazz","broadway"
;<friend> <person2>,<person4>
.
<person2>
rdf:type <person>
;<name> "Vladimir Humphrey"
;<like> "jazz","classical","vegas","musicals"
;<dislike> "broadway"
;<friend> <person3>
.
<person3>
rdf:type <person>
;<name> "Lars Ratliff"
;<like> "sports","rock","musicals"
;<dislike> "theatre","jazz","opera"
;<friend> <person1>
.
<person4>
rdf:type <person>
;<name> "Barry Roy"
;<like> "theatre"
;<dislike> "sports","jazz","musicals"
;<friend> <person5>
.
<person5>
rdf:type <person>
;<name> "Reagan Hodge"
;<like> "concerts","rock","vegas","musicals"
;<dislike> "jazz","broadway"
;<friend> <person1>
.

Loading friends.ttl into a graph named friends and querying the new graph for a list of friendships produces the following results. The query returns 6 friendships:

SELECT *
FROM <friends>
WHERE { ?person <friend> ?friend . }
ORDER BY ?person
person  | friend
--------+---------
person1 | person4
person1 | person2
person2 | person3
person3 | person1
person4 | person5
person5 | person1
6 rows

The query below generates inferences for the friends graph based on the rules for owl:TransitiveProperty. The query creates the inferences in a graph named more-friends:

 CREATE INFERENCES FROM INTO GRAPH <friends> INTO GRAPH <more-friends>

When the inferencing is complete, the following query returns the friend triples in the more-friends graph. The query filters out triples for which the same person is the subject (?person) and object (?friend):

SELECT *
FROM <more-friends>
WHERE {
  ?person <friend> ?friend.
  FILTER(?person != ?friend).
}
ORDER BY ?person
person  | friend
--------+---------
person1 | person5
person1 | person3
person2 | person5
person2 | person4
person2 | person1
person3 | person5
person3 | person2
person3 | person4
person4 | person2
person4 | person3
person4 | person1
person5 | person2
person5 | person4
person5 | person3
14 rows

Following the OWL 2 TL rules for owl:TransitiveProperty, AnzoGraph inferred 8 new friendships from the 6 friendships in the original friend graph.

Let us know your thoughts in the comments.

Topics:
anzograph ,inference ,cambridge semantics ,rdf graphs ,tutorial ,database

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}