Search in sources :

Example 1 with Graph

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();
    }
}
Also used : RepositoryConfig(org.openrdf.repository.config.RepositoryConfig) SailRepositoryConfig(org.openrdf.repository.sail.config.SailRepositoryConfig) InputStream(java.io.InputStream) StatementCollector(org.openrdf.rio.helpers.StatementCollector) Resource(org.openrdf.model.Resource) RDFParser(org.openrdf.rio.RDFParser) ConfigTemplate(org.openrdf.repository.config.ConfigTemplate) Repository(org.openrdf.repository.Repository) Graph(org.openrdf.model.Graph) LocalRepositoryManager(org.openrdf.repository.manager.LocalRepositoryManager) StringReader(java.io.StringReader) LinkedHashModel(org.openrdf.model.impl.LinkedHashModel) Test(org.junit.Test)

Example 2 with Graph

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;
}
Also used : BNode(org.openrdf.model.BNode) Statement(org.openrdf.model.Statement) JSONArray(org.json.JSONArray) URIImpl(org.openrdf.model.impl.URIImpl) URI(org.openrdf.model.URI) Date(java.util.Date) SchemaField(org.apache.solr.schema.SchemaField) SolrInputDocument(org.apache.solr.common.SolrInputDocument) Graph(org.openrdf.model.Graph) JSONObject(org.json.JSONObject) GraphImpl(org.openrdf.model.impl.GraphImpl) Literal(org.openrdf.model.Literal)

Example 3 with Graph

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();
    }
}
Also used : HashGraph(org.sbpax.impl.HashGraph) Graph(org.openrdf.model.Graph) HashGraph(org.sbpax.impl.HashGraph) RDFHandlerException(org.openrdf.rio.RDFHandlerException) URI(org.openrdf.model.URI)

Example 4 with Graph

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");
*/
}
Also used : Graph(org.openrdf.model.Graph) HashGraph(org.sbpax.impl.HashGraph) HashGraph(org.sbpax.impl.HashGraph) RDFHandlerException(org.openrdf.rio.RDFHandlerException) URI(org.openrdf.model.URI)

Example 5 with Graph

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));
}
Also used : Entry(cbit.vcell.biomodel.meta.registry.Registry.Entry) Graph(org.openrdf.model.Graph) Literal(org.openrdf.model.Literal)

Aggregations

Graph (org.openrdf.model.Graph)26 HashGraph (org.sbpax.impl.HashGraph)12 Resource (org.openrdf.model.Resource)10 HashMap (java.util.HashMap)8 Statement (org.openrdf.model.Statement)7 HashSet (java.util.HashSet)6 URI (org.openrdf.model.URI)6 RDFHandlerException (org.openrdf.rio.RDFHandlerException)5 Entry (cbit.vcell.biomodel.meta.registry.Registry.Entry)4 Literal (org.openrdf.model.Literal)4 Value (org.openrdf.model.Value)4 GraphImpl (org.openrdf.model.impl.GraphImpl)4 MiriamResource (cbit.vcell.biomodel.meta.MiriamManager.MiriamResource)3 IOException (java.io.IOException)3 URL (java.net.URL)3 URLConnection (java.net.URLConnection)3 Map (java.util.Map)3 MalformedURLException (java.net.MalformedURLException)2 Date (java.util.Date)2 Set (java.util.Set)2