use of org.openrdf.model.Graph in project incubator-rya by apache.
the class RyaAccumuloSailFactoryTest method testCreateFromTemplateName.
@Test
public void testCreateFromTemplateName() throws Exception {
LocalRepositoryManager repoman = new LocalRepositoryManager(Files.createTempDir());
repoman.initialize();
try (InputStream templateStream = RepositoryConfig.class.getResourceAsStream("RyaAccumuloSail.ttl")) {
String template = IOUtils.toString(templateStream);
final ConfigTemplate configTemplate = new ConfigTemplate(template);
final Map<String, String> valueMap = ImmutableMap.<String, String>builder().put("Repository ID", "RyaAccumuloSail").put("Repository title", "RyaAccumuloSail Store").put("Rya Accumulo user", "root").put("Rya Accumulo password", "").put("Rya Accumulo instance", "dev").put("Rya Accumulo zookeepers", "zoo1,zoo2,zoo3").put("Rya Accumulo is mock", "true").build();
final String configString = configTemplate.render(valueMap);
// final Repository systemRepo = this.state.getManager().getSystemRepository();
final Graph graph = new LinkedHashModel();
final RDFParser rdfParser = Rio.createParser(RDFFormat.TURTLE);
rdfParser.setRDFHandler(new StatementCollector(graph));
rdfParser.parse(new StringReader(configString), RepositoryConfigSchema.NAMESPACE);
final Resource repositoryNode = GraphUtil.getUniqueSubject(graph, RDF.TYPE, RepositoryConfigSchema.REPOSITORY);
final RepositoryConfig repConfig = RepositoryConfig.create(graph, repositoryNode);
repConfig.validate();
repoman.addRepositoryConfig(repConfig);
Repository r = repoman.getRepository("RyaAccumuloSail");
r.initialize();
}
}
use of org.openrdf.model.Graph in project qi4j-sdk by Qi4j.
the class SolrEntityIndexerMixin method indexEntityState.
private SolrInputDocument indexEntityState(final EntityState entityState, final SolrServer server) throws IOException, SolrServerException, JSONException {
Graph graph = new GraphImpl();
stateSerializer.serialize(entityState, false, graph);
SolrInputDocument input = new SolrInputDocument();
input.addField("id", entityState.identity().identity());
input.addField("type", first(entityState.entityDescriptor().types()).getName());
input.addField("lastModified", new Date(entityState.lastModified()));
for (Statement statement : graph) {
SchemaField field = indexedFields.get(statement.getPredicate().getLocalName());
if (field != null) {
if (statement.getObject() instanceof Literal) {
String value = statement.getObject().stringValue();
if (field.getType().getTypeName().equals("json")) {
if (value.charAt(0) == '[') {
JSONArray array = new JSONArray(value);
indexJson(input, array);
} else if (value.charAt(0) == '{') {
JSONObject object = new JSONObject(value);
indexJson(input, object);
}
} else {
input.addField(field.getName(), value);
}
} else if (statement.getObject() instanceof URI && !"type".equals(field.getName())) {
String value = statement.getObject().stringValue();
value = value.substring(value.lastIndexOf(':') + 1, value.length());
String name = field.getName();
input.addField(name, value);
} else if (statement.getObject() instanceof BNode) {
Iterator<Statement> seq = graph.match((Resource) statement.getObject(), new URIImpl("http://www.w3.org/1999/02/22-rdf-syntax-ns#li"), null, (Resource) null);
while (seq.hasNext()) {
Statement seqStatement = seq.next();
String value = seqStatement.getObject().stringValue();
value = value.substring(value.lastIndexOf(':') + 1, value.length());
input.addField(field.getName(), value);
}
}
}
}
return input;
}
use of org.openrdf.model.Graph in project vcell by virtualcell.
the class TestJPAX method main.
public static void main(String[] args) {
Graph graph = new HashGraph();
String ns = DefaultNameSpaces.EX.uri;
URI r1 = graph.getValueFactory().createURI(ns + "r1");
URI pe1 = graph.getValueFactory().createURI(ns + "pe1");
URI pe2 = graph.getValueFactory().createURI(ns + "pe2");
graph.add(r1, RDF.TYPE, BioPAX3.BiochemicalReaction);
graph.add(pe1, RDF.TYPE, BioPAX3.Protein);
graph.add(pe2, RDF.TYPE, BioPAX3.Protein);
graph.add(r1, BioPAX3.left, pe1);
graph.add(r1, BioPAX3.right, pe2);
try {
Map<String, String> nsMap = DefaultNameSpaces.defaultMap.convertToMap();
SesameRioUtil.writeRDFToStream(System.out, graph, nsMap, RDFFormat.RDFXML);
} catch (RDFHandlerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.openrdf.model.Graph in project vcell by virtualcell.
the class VcmlOmexConverter method main.
public static void main(String[] args) {
Graph graph = new HashGraph();
// http://example/org/
String ns = DefaultNameSpaces.EX.uri;
// http://example/org/r1
URI r1 = graph.getValueFactory().createURI(ns + "r1");
URI pe1 = graph.getValueFactory().createURI(ns + "pe1");
URI pe2 = graph.getValueFactory().createURI(ns + "pe2");
URI ce3 = graph.getValueFactory().createURI(ns + "ce3");
// add the reaction to the graph, it'll look like this:
graph.add(r1, RDF.TYPE, BioPAX3.BiochemicalReaction);
graph.add(pe1, RDF.TYPE, BioPAX3.Protein);
graph.add(pe2, RDF.TYPE, BioPAX3.Protein);
// graph.add(ce3, RDF.TYPE, BioPAX3.Catalysis);
graph.add(r1, BioPAX3.left, pe1);
// add to reaction a child named right, it'll look like this
graph.add(r1, BioPAX3.right, pe2);
// add to reaction a child named right, it'll look like this
graph.add(pe2, BioPAX3.Catalysis, ce3);
try {
Map<String, String> nsMap = DefaultNameSpaces.defaultMap.convertToMap();
SesameRioUtil.writeRDFToStream(System.out, graph, nsMap, RDFFormat.RDFXML);
System.out.println("here");
} catch (RDFHandlerException e) {
e.printStackTrace();
}
System.out.println("finished");
/*
Graph graph = new HashGraph();
Graph schema = new HashGraph();
ValueFactory factory = ValueFactoryImpl.getInstance();
String descriptionLocation = "http://omex-library.org/biomodel_12345678.omex";
URI descriptionURI = ValueFactoryImpl.getInstance().createURI(descriptionLocation);
Literal descTitle = OntUtil.createTypedString(schema, "Publication title");
URI authorProperty = OntUtil.createDatatypeProperty(schema, DefaultNameSpaces.RDF.uri + "contributor");
URI isDescribedBy = OntUtil.createObjectProperty(schema, DefaultNameSpaces.BQMODEL.uri + "isDescribedBy");
URI is = OntUtil.createObjectProperty(schema, DefaultNameSpaces.BQMODEL.uri + "is");
// alternate way, using factory
// URI isDescribedBy = factory.createURI(DefaultNameSpaces.BQMODEL.uri, "isDescribedBy");
// OntUtil.addTypedComment(schema, isDescribedBy, "A relationship"); // shema, resource, comment
// Literal aaa = factory.createLiteral("aaa label");
// URI ccc = OntUtil.createAnnotationProperty(graph, uri); // graph, uri
// URI ddd = OntUtil.createURIIndividual(graph, uri, RDF.TYPE); // graph, uri, RDF.TYPE
// URI fff = SBPAX3Util.addSubEntity(graph, is, descriptionURI, sbTerm); // graph, uri, parent, sbTerm
// OntUtil.addEnglishComment(schema, creatorProperty, "The authors of this, one per property value."); // schema, resource, comment
// BNode node = OntUtil.createDataRange(schema, "Dan Vasilescu");
URI contributor = factory.createURI(DefaultNameSpaces.DUBLIN_CORE.uri, "contributor");
graph.add(PubMet.rdfURI, RDF.TYPE, authorProperty); // add to the rdf root
graph.add(descriptionURI, RDF.TYPE, PubMet.Description); // <rdf:Description rdf:about='http://omex-library.org/Monkeyflower_pigmentation_v2.omex'>
graph.add(descriptionURI, PubMet.Creator, PubMet.rdfsURI); // <rdfs:creator rdf:resource="http://www.w3.org/2000/01/rdf-schema#"/>
graph.add(descriptionURI, isDescribedBy, descTitle);
try {
Map<String, String> nsMap = DefaultNameSpaces.defaultMap.convertToMap();
SesameRioUtil.writeRDFToStream(System.out, graph, nsMap, RDFFormat.RDFXML);
String ret = SesameRioUtil.writeRDFToString(graph, nsMap, RDFFormat.RDFXML);
System.out.println("here");
} catch (RDFHandlerException e) {
e.printStackTrace();
}
System.out.println("finished");
*/
}
use of org.openrdf.model.Graph in project vcell by virtualcell.
the class VCMetaDataMiriamManager method addDate.
public void addDate(Identifiable identifiable, DateQualifier dateQualifier, DublinCoreDate date) {
Entry entry = vcMetaData.getRegistry().getEntry(identifiable);
if (entry.getResource() == null) {
String newURI = vcMetaData.getRegistry().generateFreeURI(identifiable);
entry.setURI(vcMetaData.getRdfData(), newURI);
}
Graph rdfData = vcMetaData.getRdfData();
Literal dateLiteral = rdfData.getValueFactory().createLiteral(date.getDateString());
rdfData.add(entry.getResource(), dateQualifier.getProperty(), dateLiteral);
vcMetaData.fireAnnotationEventListener(new VCMetaData.AnnotationEvent(identifiable));
}
Aggregations