Labeled Property Graphs (RDF*)

AnzoGraph uses the RDF* proposed W3C standard for labeled property graph support. Labeled property graphs enable users to add properties to triples that further define the relationships in the data, such as properties that describe start and end dates, the provenance of the data, the weight, score, or veracity of the data, and so on. For technical details about the RDF* implementation, see Foundations of an Alternative Approach to Reification in RDF.

This topic provides information about loading and inserting properties and querying property graphs.

Defining Properties in Turtle Files

To define a property for a triple in a Turtle load file, wrap the triplet in double arrow heads ( << >>), and then specify the property name and value for that triple at the end of the triplet:

<< subject predicate object >> property_URI property_value .

For example, the TTL file contents below include properties that further define the like, dislike, and friend relationships in the triples. The file adds a weight property to define how much person3 likes or dislikes certain types of events, and the file adds startDate and endDate properties to friend predicates to define the start and end dates of friendships. This example modifies the person3 data in one of the sample Tickit data set load files:

  rdf:type <person>;
  <card> "4984932249480735"^^xsd:long;
  <birthday> "1963-07-02"^^xsd:date;
  <ssn> 503703220;
  <firstname> "Lars";
  <lastname> "Ratliff";
  <city> "High Point";
  <state> "NY";
  <email> "";
  <phone> "(624) 767-2465".
<< <person3> <like> "sports">> <weight> 8.
<< <person3> <like> "rock">> <weight> 9.
<< <person3> <like> "musicals">> <weight> 4.
<< <person3> <dislike> "theatre">> <weight> 5.
<< <person3> <dislike> "jazz">> <weight> 9.
<< <person3> <dislike> "opera">> <weight> 10.
<< <person3> <friend> <person8563> >> <startDate> "1990-01-04"^^xsd:date.
<< <person3> <friend> <person38436> >> <startDate> "2000-04-27"^^xsd:date.
<< <person3> <friend> <person11979> >> <startDate> "2004-11-09"^^xsd:date.
<< <person3> <friend> <person11979> >> <endDate> "2012-07-17"^^xsd:date.
<person3> <friend> <person8639>,<person18536>,<person42975>,<person47376>,

The example above contains both compact and long Turtle notation. When defining properties in files, tuples that contain properties must include the complete reference triple (subject, predicate, and object). Properties cannot be added to triples specified in compact notation. In addition, specify one property per triplet. To define multiple properties for the same triplet, list the triplet multiple times. For example, the following lines in the example above define two properties (startDate and endDate) for the person3 friend person11979 triple:

<< <person3> <friend> <person11979> >> <startDate> "2004-11-09"^^xsd:date.
<< <person3> <friend> <person11979> >> <endDate> "2012-07-17"^^xsd:date.

Note: By default, the sample Tickit data set already includes startDate and endDate properties for the friend predicates. The example above defines start and end date properties for illustrative purposes.

Defining Properties in INSERT Queries

Users can create property graphs using INSERT Syntax and INSERT DATA Syntax to insert triples and properties or add properties to existing triples. To define properties in INSERT statements, use the same syntax as Turtle files: wrap triplets in double arrow heads ( << >>), and then specify the property name and value for that triple at the end of the triplet.

<< subject predicate object >> property_URI property_value .

For example, the INSERT DATA statement below adds weight properties to the like and dislike predicates for person3.

INSERT DATA { GRAPH <tickit> {
  << <person3> <dislike> "jazz" >> <weight> 9 .
  << <person3> <dislike> "theatre" >> <weight> 5 .
  << <person3> <dislike> "opera" >> <weight> 10 .
  << <person3> <like> "sports" >> <weight> 8 .
  << <person3> <like> "rock" >> <weight> 9 .
  << <person3> <like> "musicals" >> <weight> 4 .

Querying Property Graphs

To return properties and their values when analyzing data sets, include the following property graph syntax in graph and triple patterns:

<< subject predicate object >> property_URI property_value .

For example, the following query returns the properties that were defined in the INSERT DATA query above.

FROM <tickit>
  <<?person ?p ?likes_or_dislikes>> ?property ?value.
  FILTER(?p=<like> || ?p=<dislike>)
person  | p       | likes_or_dislikes | property | value
person3 | dislike | jazz              | weight   |     9
person3 | dislike | opera             | weight   |    10
person3 | dislike | theatre           | weight   |     5
person3 | like    | rock              | weight   |     9
person3 | like    | musicals          | weight   |     4
person3 | like    | sports            | weight   |     8
6 rows

This example returns a list of the properties in the Tickit graph and lists the number of times each property is referenced in the graph:

SELECT ?property (COUNT(?property) AS ?times_used)
FROM <tickit>
  <<?s ?p ?o>> ?property ?value
GROUP BY ?property
ORDER BY desc(?times_used)
property  | times_used
startDate |    1729764
endDate   |     173036
weight    |          6
3 rows
Related Topics