Skip to main content
Jump to: navigation, search

Difference between revisions of "XDI4j Tutorial 3"

m (logo, category, left menu)
Line 1: Line 1:
{{#eclipseproject:technology.higgins}}
+
{{#eclipseproject:technology.higgins|eclipse_custom_style.css}}
 
[[Image:Higgins_logo_76Wx100H.jpg|right]]
 
[[Image:Higgins_logo_76Wx100H.jpg|right]]
 
== Example ==
 
== Example ==

Revision as of 10:03, 16 December 2008

{{#eclipseproject:technology.higgins|eclipse_custom_style.css}}

Higgins logo 76Wx100H.jpg

Example

This example app shows how to work with dictionary statements.

It also shows auxiliary functions for metadata and timestamps.

package org.eclipse.higgins.xdi4j.tutorial;

import java.util.Date;

import org.eclipse.higgins.xdi4j.Graph;
import org.eclipse.higgins.xdi4j.GraphFactory;
import org.eclipse.higgins.xdi4j.Predicate;
import org.eclipse.higgins.xdi4j.Subject;
import org.eclipse.higgins.xdi4j.dictionary.Dictionary;
import org.eclipse.higgins.xdi4j.impl.memory.MemoryGraphFactory;
import org.eclipse.higgins.xdi4j.io.XDIWriter;
import org.eclipse.higgins.xdi4j.io.XDIWriterRegistry;
import org.eclipse.higgins.xdi4j.metadata.Metadata;
import org.eclipse.higgins.xdi4j.xri3.impl.XRI3Segment;

/**
 * This example app shows how to work with dictionary statements.
 * It also shows auxiliary functions for metadata and timestamps.
 * 
 * @author msabadello at parityinc dot not
 *
 */
public class Tutorial3 {

	public static void main(String[] args) throws Exception {

		GraphFactory factory = MemoryGraphFactory.getInstance();
		Graph graph = factory.openGraph();

		// let's create a subject in the graph

		Subject markus = graph.createSubject(new XRI3Segment("=markus"));

		// let's create an aggregate subject for =markus

		Subject markusHome = Dictionary.createAggregateSubject(markus, new XRI3Segment("+home"));

		// let's create a composite predicate for =markus

		Predicate email = Dictionary.createCompositePredicate(markusHome, new XRI3Segment("+email"));

		// let's create a literal

		email.createLiteral("markus.sabadello@gmail.com");

		// let's remember when we last modified =markus+home

		Metadata.addTimestamp(markusHome, new Date());

		// after our graph is filled, we can output it

		XDIWriter writer = XDIWriterRegistry.forFormat("X3D");
		writer.write(graph, System.out, null);

		graph.close();
	}
}

Back to the top