Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
XDI4j Tutorial 3
{{#eclipseproject:technology.higgins|eclipse_custom_style.css}}
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(); } }