Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "XDI4j Tutorial 3"

(New page: == Example == This example app shows how to work with dictionary statements. It also shows auxiliary functions for metadata and timestamps. <pre> package org.eclipse.higgins.xdi4j.tutor...)
 
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
{{#eclipseproject:technology.higgins|eclipse_custom_style.css}}
 +
[[Image:Higgins_logo_76Wx100H.jpg|right]]
 
== Example ==
 
== Example ==
  
Line 57: Line 59:
 
// after our graph is filled, we can output it
 
// after our graph is filled, we can output it
  
XDIWriter writer = XDIWriterRegistry.forFormat("X3D");
+
XDIWriter writer = XDIWriterRegistry.forFormat("X3 Simple");
 
writer.write(graph, System.out, null);
 
writer.write(graph, System.out, null);
  
Line 64: Line 66:
 
}
 
}
 
</pre>
 
</pre>
 +
 +
[[Category:Higgins XDI4j]]

Latest revision as of 11:46, 1 September 2009

{{#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("X3 Simple");
		writer.write(graph, System.out, null);

		graph.close();
	}
}

Back to the top