Java Code Examples for org.apache.jena.riot.RDFDataMgr#write()

The following examples show how to use org.apache.jena.riot.RDFDataMgr#write() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: xcurator   File: UpdateProgrammatic.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String []args)
{
    Dataset dataset = DatasetFactory.createTxnMem() ;
    
    UpdateRequest request = UpdateFactory.create() ;
    
    request.add(new UpdateDrop(Target.ALL)) ;
    request.add(new UpdateCreate("http://example/g2")) ;
    request.add(new UpdateLoad("file:etc/update-data.ttl", "http://example/g2")) ;
    UpdateAction.execute(request, dataset) ;
    
    System.out.println("# Debug format");
    SSE.write(dataset) ;
    
    System.out.println();
    
    System.out.println("# N-Quads: S P O G") ;
    RDFDataMgr.write(System.out, dataset, Lang.NQUADS) ;
}
 
Example 2
Source Project: rdf-delta   File: TestRDFChangesGraph.java    License: Apache License 2.0 6 votes vote down vote up
private Graph replay() {
    IO.close(bout);
    final boolean DEBUG = false;

    if ( DEBUG ) {
        System.out.println("== Graph ==");
        RDFDataMgr.write(System.out, baseGraph, Lang.NQ);
        System.out.println("== Replay ==");
        String x = StrUtils.fromUTF8bytes(bout.toByteArray());
        System.out.print(x);
        System.out.println("== ==");
    }

    // A completely separate graph (different dataset)
    Graph graph2 = txnGraph();

    try(ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray())) {
        RDFPatchOps.applyChange(graph2, bin);
        if ( DEBUG ) {
            System.out.println("== Graph outcome ==");
            RDFDataMgr.write(System.out, graph2, Lang.NT);
            System.out.println("== ==");
        }
        return graph2;
    } catch (IOException ex) { IO.exception(ex); return null; }
}
 
Example 3
Source Project: xcurator   File: ExRIOT_out2.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String[] args)
{
    Model model = RDFDataMgr.loadModel("D.ttl") ;
    System.out.println() ;
    System.out.println("#### ---- Write as TriG") ;
    System.out.println() ;
    // This wil be the default graph of the dataset written.
    RDFDataMgr.write(System.out, model, Lang.TRIG) ;
    
    // Loading Turtle as Trig reads into the default graph.
    Dataset dataset = RDFDataMgr.loadDataset("D.ttl") ;
    System.out.println() ;
    System.out.println("#### ---- Write as NQuads") ;
    System.out.println() ;
    RDFDataMgr.write(System.out, dataset, Lang.NQUADS) ;
}
 
Example 4
Source Project: trellis   File: DBResourceService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Serialize a graph into a string of N-Triples.
 * @param graph the RDF graph
 * @return the serialized form
 */
static String serializeGraph(final Graph graph) {
    try (final StringWriter writer = new StringWriter()) {
        RDFDataMgr.write(writer, toJena(graph), NTRIPLES);
        return writer.toString();
    } catch (final IOException ex) {
        throw new UncheckedIOException("Error writing extension data", ex);
    }
}
 
Example 5
/**
 * Executes a given CONSTRUCT query against a given dataset.
 * 
 * @param data the mistery guest containing test data (query and dataset)
 * @throws Exception never, otherwise the test fails.
 */
protected void constructTest(final MisteryGuest data) throws Exception {
	load(data);
	
	try {
		inMemoryExecution = QueryExecutionFactory.create(
				QueryFactory.create(queryString(data.query)), memoryDataset);
		
		assertTrue(
				Arrays.toString(data.datasets) + ", " + data.query,
				inMemoryExecution.execConstruct().isIsomorphicWith(
						SOLRDF_CLIENT.construct(queryString(data.query))));
	} catch (final Throwable error) {
		StringWriter writer = new StringWriter();
		RDFDataMgr.write(writer, SOLRDF_CLIENT.construct(queryString(data.query)), RDFFormat.NTRIPLES);
		log.debug("JNS\n" + writer);
		
		QueryExecution debugExecution = QueryExecutionFactory.create(
				QueryFactory.create(queryString(data.query)), memoryDataset);
		
		writer = new StringWriter();
		RDFDataMgr.write(writer, debugExecution.execConstruct(), RDFFormat.NTRIPLES);
		
		log.debug("MEM\n" + writer);
		
		debugExecution.close();
		throw error;
	} 
}
 
Example 6
/**
 * Executes a given CONSTRUCT query against a given dataset.
 * 
 * @param data the mistery guest containing test data (query and dataset)
 * @throws Exception never, otherwise the test fails.
 */
protected void describeTest(final MisteryGuest data) throws Exception {
	load(data);
	
	final Query query = QueryFactory.create(queryString(data.query));
	try {
		inMemoryExecution = QueryExecutionFactory.create(query, memoryDataset);
		
		assertTrue(
				Arrays.toString(data.datasets) + ", " + data.query,
				inMemoryExecution.execDescribe().isIsomorphicWith(
						SOLRDF_CLIENT.describe(queryString(data.query))));
	} catch (final Throwable error) {
		StringWriter writer = new StringWriter();
		RDFDataMgr.write(writer, SOLRDF_CLIENT.describe(queryString(data.query)), RDFFormat.NTRIPLES);
		log.debug("JNS\n" + writer);
		
		QueryExecution debugExecution = QueryExecutionFactory.create(query, memoryDataset);
		writer = new StringWriter();
		RDFDataMgr.write(writer, debugExecution.execDescribe(), RDFFormat.NTRIPLES);
		
		log.debug("MEM\n" + writer);
		
		debugExecution.close();
		throw error;
	} 
}
 
Example 7
public static void perspectiveRelationsToTrig (String pathToTrigFile,
                                               KafSaxParser kafSaxParser,
                                               String project,
                                               ArrayList<PerspectiveObject> sourcePerspectiveObjects,
                                               ArrayList<PerspectiveObject> authorPerspectiveObjects) {
        try {
            OutputStream fos = new FileOutputStream(pathToTrigFile);
            Dataset ds = TDBFactory.createDataset();
            Model defaultModel = ds.getDefaultModel();
            ResourcesUri.prefixModelGaf(defaultModel);
            ResourcesUri.prefixModelNwr(defaultModel);
            defaultModel.setNsPrefix("rdf", ResourcesUri.rdf);
            defaultModel.setNsPrefix("rdfs", ResourcesUri.rdfs);
            String docId = kafSaxParser.getKafMetaData().getUrl().replaceAll("#", "HASH");
            if (!docId.toLowerCase().startsWith("http")) {
                docId = ResourcesUri.nwrdata + project + "/" + docId;
            }
            JenaSerialization.addDocMetaData(docId, kafSaxParser, project);
            String attrBase = kafSaxParser.getKafMetaData().getUrl()+"_"+"s";
            JenaSerialization.addJenaPerspectiveObjects(attrBase, ResourcesUri.grasp, "wasAttributedTo", sourcePerspectiveObjects, 1);
            attrBase = kafSaxParser.getKafMetaData().getUrl()+"_"+"d";
            JenaSerialization.addJenaPerspectiveObjects(attrBase, ResourcesUri.prov, "wasDerivedFrom", authorPerspectiveObjects, sourcePerspectiveObjects.size()+1);
            RDFDataMgr.write(fos, ds, RDFFormat.TRIG_PRETTY);
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
}
 
Example 8
public static void main(String[] args) {
	String sample = "{     \"_id\" : ObjectId(\"560c9d741ee8203c53a63569\"),     \"rn\" : \"CONTENT_INST_5\",     \"ty\" : 4,     \"ri\" : \"CONTENT_INST_5\",     \"pi\" : \"CONTAINER_37\",     \"lbl\" : [          \"cnt-switch\"     ],     \"cr\" : \"C_AE-D-GASLOCK1004\",     \"cnf\" : \"text/plain:0\",     \"cs\" : 3,     \"con\" : \"Off\",     \"_uri\" : \"/herit-in/herit-cse/ae-gaslock1004/cnt-switch/CONTENT_INST_5\",     \"ct\" : \"20151001T114156\",     \"lt\" : \"20151001T114156\" , \"or\":\"http://www.pineone.com/campus/StateCondition\" }";
	Gson gson = new Gson();
	OneM2MContentInstanceDTO cont = gson.fromJson(sample, OneM2MContentInstanceDTO.class);
	System.out.println(cont);

	OneM2MContentInstanceMapper mapper = new OneM2MContentInstanceMapper(cont);
	Model model = ModelFactory.createDefaultModel();
	model.add(mapper.from());

	// 스트링 변환부분
	RDFDataMgr.write(System.out, model, RDFFormat.NTRIPLES);
}
 
Example 9
public static void main(String[] args) throws IOException, InterruptedException {

		PROPERTY_SURFACE_FORMS = DIRECTORY + "property_surface_forms.ttl";

		// create an empty model
		Model inputModel = ModelFactory.createDefaultModel();

		// use the FileManager to find the input file
		InputStream in = FileManager.get().open(DBPEDIA_PROPERTY_FILE);
		if (in == null) {
			throw new IllegalArgumentException("File: " + DBPEDIA_PROPERTY_FILE + " not found");
		}

		// read the RDF/XML file
		inputModel.read(in, null, "N-TRIPLE");
		inputModel.write(System.out);

		Model outputModel = ModelFactory.createDefaultModel();
		QueryExecution qExec = QueryExecutionFactory
				.create("SELECT ?s  ?label WHERE{?s a <http://www.w3.org/1999/02/22-rdf-syntax-ns#Property>."
						+ " ?s <http://www.w3.org/2000/01/rdf-schema#label> ?label. }", inputModel);
		ResultSet rs = qExec.execSelect();
		System.out.println(qExec);
		while (rs.hasNext()) {
			QuerySolution qs = rs.next();
			Resource uri = qs.get("?s").asResource();
			RDFNode label = qs.get("?label");
			StatementImpl s = new StatementImpl(uri, RDFS.label, label);
			outputModel.add(s);

		}

		qExec.close();

		FileOutputStream outputFile = new FileOutputStream(PROPERTY_SURFACE_FORMS);
		RDFDataMgr.write(outputFile, outputModel, RDFFormat.NTRIPLES);
	}
 
Example 10
public static void main(String[] args) throws IOException, InterruptedException {

		CLASS_SURFACE_FORMS = DIRECTORY + "class_surface_forms.ttl";

		// create an empty model
		Model inputModel = ModelFactory.createDefaultModel();

		// use the FileManager to find the input file
		InputStream in = FileManager.get().open(DBPEDIA_CLASSE_FILE);
		if (in == null) {
			throw new IllegalArgumentException("File: " + DBPEDIA_CLASSE_FILE + " not found");
		}

		// read the RDF/XML file
		inputModel.read(in, null, "N-TRIPLE");

		Model outputModel = ModelFactory.createDefaultModel();
		QueryExecution qExec = QueryExecutionFactory
				.create("SELECT ?s ?label WHERE{?s a <http://www.w3.org/2002/07/owl#Class>."
						+ " ?s <http://www.w3.org/2000/01/rdf-schema#label> ?label. "
						+ "FILTER (lang(?label) = \"en\")}", inputModel);
		ResultSet rs = qExec.execSelect();
		while (rs.hasNext()) {
			QuerySolution qs = rs.next();
			Resource uri = qs.get("?s").asResource();
			RDFNode label = qs.get("?label");
			StatementImpl s = new StatementImpl(uri, RDFS.label, label);
			outputModel.add(s);

		}

		qExec.close();

		FileOutputStream outputFile = new FileOutputStream(CLASS_SURFACE_FORMS);
		RDFDataMgr.write(outputFile, outputModel, RDFFormat.NTRIPLES);

	}
 
Example 11
Source Project: SDA   File: OneM2MAEDTO.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void main(String[] args) {
	String sample = " {     \"_id\" : ObjectId(\"561e1e1e1ee82041fac258b6\"),     \"rn\" : \"SAE_0\",     \"ty\" : 2,     \"ri\" : \"SAE_0\",     \"pi\" : \"herit-in\",     \"lbl\" : [          \"home1\",          \"home_service\"     ],     \"et\" : \"20151203T122321\",     \"at\" : [          \"//onem2m.hubiss.com/cse1\",          \"//onem2m.hubiss.com/cse2\"     ],     \"aa\" : [          \"poa\",          \"apn\"     ],     \"apn\" : \"onem2mPlatformAdmin\",     \"api\" : \"NHeritAdmin\",     \"aei\" : \"/SAE_0\",     \"poa\" : [          \"10.101.101.111:8080\"     ],     \"rr\" : false,     \"_uri\" : \"/herit-in/herit-cse/SAE_0\",     \"ct\" : \"20151014T181926\",     \"lt\" : \"20151014T181926\" }";
	Gson gson = new Gson();
	OneM2MAEDTO cont = gson.fromJson(sample, OneM2MAEDTO.class);


	System.out.println(cont);
	
	OneM2MAEMapper mapper = new OneM2MAEMapper(cont);
	Model model = ModelFactory.createDefaultModel();
	model.add(mapper.from());
	
	//스트링 변환부분
	RDFDataMgr.write(System.out, model, RDFFormat.NTRIPLES);
}
 
Example 12
/**
 * Throws an exception if the syntax is not SPARQL
 * 
 * @throws IOException from underlying {@link OutputStream}
 * @throws ModelRuntimeException for errors using the model
 */
@Override
public void writeTo(OutputStream out, Syntax syntax) throws ModelRuntimeException {
	assertModel();

	RDFDataMgr.write(out, this.jenaModel, getJenaLang(syntax));
}
 
Example 13
public static void main(String[] args) {
//		String sample = "{     \"_id\" : ObjectId(\"560c9d741ee8203c53a63569\"),     \"rn\" : \"CONTENT_INST_5\",     \"ty\" : 4,     \"ri\" : \"CONTENT_INST_5\",     \"pi\" : \"CONTAINER_37\",     \"lbl\" : [          \"cnt-switch\"     ],     \"cr\" : \"C_AE-D-GASLOCK1004\",     \"cnf\" : \"text/plain:0\",     \"cs\" : 3,     \"con\" : \"Off\",     \"_uri\" : \"/herit-in/herit-cse/ae-gaslock1004/cnt-switch/CONTENT_INST_5\",     \"ct\" : \"20151001T114156\",     \"lt\" : \"20151001T114156\" , \"or\":\"http://www.pineone.com/campus/StateCondition\" }";
		String sample = 
				"{ "+
				"	    \"_id\" : ObjectId(\"560c9b1e1ee8203c53a63554\"),"+
				"	    \"rn\" : \"CONTENT_INST_0\","+
				"	    \"ty\" : 4,"+
				"	    \"ri\" : \"CONTENT_INST_0\","+
				"	    \"pi\" : \"CONTAINER_15\","+
				"	    \"lbl\" : [ "+
				"	        \"cnt-temperature\""+
				"	    ],"+
				"	    \"cr\" : \"C_AE-D-GASLOCK1001\","+
				"	    \"cnf\" : \"text/plain:0\","+
				"	    \"cs\" : 2,"+
				"	    \"con\" : \"13\","+
				"	    \"_uri\" : \"/herit-in/herit-cse/ae-gaslock1001/cnt-temperature/CONTENT_INST_0\","+
				"	    \"ct\" : \"20151001T113158\","+
				"	    \"lt\" : \"20151001T113158\" "+
				"	} " ;
		Gson gson = new Gson();
		OneM2MContentInstanceDTO cont = gson.fromJson(sample, OneM2MContentInstanceDTO.class);
		System.out.println(cont);


		OneM2MContentInstanceMapper mapper = new OneM2MContentInstanceMapper(cont);
		mapper = new OneM2MContentInstanceMapper(cont);
		Model model = ModelFactory.createDefaultModel();
		model.add(mapper.from());

		// 스트링 변환부분
		RDFDataMgr.write(System.out, model, RDFFormat.NTRIPLES);
	}
 
Example 14
public static void main(String[] args) {
	String sample = "{     \"_id\" : ObjectId(\"560c9d741ee8203c53a63569\"),     \"rn\" : \"CONTENT_INST_5\",     \"ty\" : 4,     \"ri\" : \"CONTENT_INST_5\",     \"pi\" : \"CONTAINER_37\",     \"lbl\" : [          \"cnt-switch\"     ],     \"cr\" : \"C_AE-D-GASLOCK1004\",     \"cnf\" : \"text/plain:0\",     \"cs\" : 3,     \"con\" : \"Off\",     \"_uri\" : \"/herit-in/herit-cse/ae-gaslock1004/cnt-switch/CONTENT_INST_5\",     \"ct\" : \"20151001T114156\",     \"lt\" : \"20151001T114156\" , \"or\":\"http://www.pineone.com/campus/StateCondition\" }";
	Gson gson = new Gson();
	OneM2MContentInstanceDTO cont = gson.fromJson(sample, OneM2MContentInstanceDTO.class);
	System.out.println(cont);

	OneM2MContentInstanceMapper mapper = new OneM2MContentInstanceMapper(cont);
	Model model = ModelFactory.createDefaultModel();
	model.add(mapper.from());

	// 스트링 변환부분
	RDFDataMgr.write(System.out, model, RDFFormat.NTRIPLES);
}
 
Example 15
static public void serializeJenaSimpleCompositeEvents (OutputStream stream,
                                                 ArrayList<CompositeEvent> compositeEvents,SimpleTaxonomy simpleTaxonomy, HashMap<String, String> rename) {




    createSimpleModels();
    for (int c = 0; c < compositeEvents.size(); c++) {
        CompositeEvent compositeEvent = compositeEvents.get(c);
        addJenaSimpleCompositeEvent(compositeEvent, simpleTaxonomy,rename);
    }
    try {
        RDFDataMgr.write(stream, ds, RDFFormat.TRIG_PRETTY);
    } catch (Exception e) {
      //  e.printStackTrace();
    }


}
 
Example 16
/**
 * DBObject나 String값을 triple로 변환
 * @param doc
 * @return String
 * @throws Exception
 */
public String getTriple(Object doc) throws Exception {
	Gson gson = new Gson();
	StringWriter sw = new StringWriter();
	String returnStr = "";
	String ri = Utils.NotSupportingType;
	OneM2MContentInstanceDTO contextInstanceDTO = new OneM2MContentInstanceDTO();

	int ty = -1;

	if (doc instanceof DBObject) {
		DBObject docT = (DBObject) doc;
		ty = (Integer) docT.get("ty");
	} else if (doc instanceof String) {
		contextInstanceDTO = gson.fromJson((String)doc, OneM2MContentInstanceDTO.class);
		ty = Integer.parseInt(contextInstanceDTO.getTy());
	}

	if (ty == 5) {
		log.debug("=== ri : "+ri+",  ty : "+ty+" ====>exclude");
		sw.flush();
	} else if (ty == 4) {
		if (doc instanceof DBObject) {
			contextInstanceDTO = gson.fromJson(gson.toJson(doc), OneM2MContentInstanceDTO.class);
			
		} else if (doc instanceof String) {
			contextInstanceDTO = gson.fromJson((String)doc, OneM2MContentInstanceDTO.class);
		}
		OneM2MContentInstanceMapper mapper = new OneM2MContentInstanceMapper(contextInstanceDTO);
	
		Model model = ModelFactory.createDefaultModel();
		model.add(mapper.from());
		
		this.setParentResourceUri(mapper.getParentResourceUri());
		this.setInstanceUri(mapper.getInstanceUri());
		this.setInstanceValue(mapper.getContent());
		
		//gooper
		this.setCreateDate(mapper.getCreateDate());
		this.setLastModifiedDate(mapper.getLastModifiedDate());

		// 스트링 변환부분
		RDFDataMgr.write(sw, model, RDFFormat.NTRIPLES);

		returnStr = sw.toString();
		sw.flush();
		sw.close();
		
		if(! model.isClosed()) {
			model.close();
		}
		
		if(model != null) {
			model = null;
		}
		if(mapper != null) {
			mapper.close();
			mapper = null;
		}
		if(doc != null) {
			doc = null;
		}
	} else if (ty == 3) {
		log.debug("=== ri: "+ri+",  ty : "+ty+" ====>exclude");			
		sw.flush();
	} else if (ty == 2) {
		log.debug("=== ri : "+ri+",  ty : "+ty+" ====>exclude");			
		sw.flush();
	} else if (ty == 1) {
		log.debug("=== ri : "+ri+",  ty : "+ty+" ====>exclude");			
		sw.flush();
	} else if (ty == 0) {
		log.debug("=== ri : "+ri+",  ty : "+ty+" ====>exclude");			
		sw.flush();
	} else {
		log.debug("Unknown ty("+ty+") value ====>exclude ");
	}
	
	return returnStr;
}
 
Example 17
/**
 * DBObject나 String값을 triple로 변환
 * @param doc
 * @return String
 * @throws Exception
 */
public String getTriple(Object doc) throws Exception {
	Gson gson = new Gson();
	StringWriter sw = new StringWriter();
	String returnStr = "";
	String ri = Utils.NotSupportingType;
	OneM2MContentInstanceDTO contextInstanceDTO = new OneM2MContentInstanceDTO();

	int ty = -1;

	if (doc instanceof DBObject) {
		DBObject docT = (DBObject) doc;
		ty = (Integer) docT.get("ty");
	} else if (doc instanceof String) {
		contextInstanceDTO = gson.fromJson((String)doc, OneM2MContentInstanceDTO.class);
		ty = Integer.parseInt(contextInstanceDTO.getTy());
	}

	if (ty == 5) {
		log.debug("=== ri : "+ri+",  ty : "+ty+" ====>exclude");
		sw.flush();
	} else if (ty == 4) {
		if (doc instanceof DBObject) {
			contextInstanceDTO = gson.fromJson(gson.toJson(doc), OneM2MContentInstanceDTO.class);
			
		} else if (doc instanceof String) {
			contextInstanceDTO = gson.fromJson((String)doc, OneM2MContentInstanceDTO.class);
		}
		OneM2MContentInstanceMapper mapper = new OneM2MContentInstanceMapper(contextInstanceDTO);
	
		Model model = ModelFactory.createDefaultModel();
		model.add(mapper.from());
		
		this.setParentResourceUri(mapper.getParentResourceUri());
		this.setInstanceUri(mapper.getInstanceUri());
		this.setInstanceValue(mapper.getContent());
		
		//gooper
		this.setCreateDate(mapper.getCreateDate());
		this.setLastModifiedDate(mapper.getLastModifiedDate());

		// 스트링 변환부분
		RDFDataMgr.write(sw, model, RDFFormat.NTRIPLES);

		returnStr = sw.toString();
		sw.flush();
		sw.close();
		
		if(! model.isClosed()) {
			model.close();
		}
		
		if(model != null) {
			model = null;
		}
		if(mapper != null) {
			mapper.close();
			mapper = null;
		}
		if(doc != null) {
			doc = null;
		}
	} else if (ty == 3) {
		log.debug("=== ri: "+ri+",  ty : "+ty+" ====>exclude");			
		sw.flush();
	} else if (ty == 2) {
		log.debug("=== ri : "+ri+",  ty : "+ty+" ====>exclude");			
		sw.flush();
	} else if (ty == 1) {
		log.debug("=== ri : "+ri+",  ty : "+ty+" ====>exclude");			
		sw.flush();
	} else if (ty == 0) {
		log.debug("=== ri : "+ri+",  ty : "+ty+" ====>exclude");			
		sw.flush();
	} else {
		log.debug("Unknown ty("+ty+") value ====>exclude ");
	}
	
	return returnStr;
}
 
Example 18
Source Project: fcrepo-import-export   File: Exporter.java    License: Apache License 2.0 4 votes vote down vote up
private void exportRdf(final URI uri, final URI binaryURI)
        throws FcrepoOperationFailedException {
    final File file = fileForURI(uri, null, null, config.getBaseDirectory(), config.getRdfExtension());
    if (file == null) {
        logger.info("Skipping {}", uri);
        return;
    } else if (file.exists()) {
        logger.info("Already exported {}", uri);
        return;
    }

    GetBuilder getBuilder = client().get(uri).accept(config.getRdfLanguage());
    if (config.retrieveInbound()) {
        getBuilder = getBuilder.preferRepresentation(
            Arrays.asList(URI.create(INBOUND_REFERENCES.getURI())), null);
    }

    try (FcrepoResponse response = getBuilder.perform()) {
        checkValidResponse(response, uri, config.getUsername());
        logger.info("Exporting rdf: {}", uri);

        final String responseBody = IOUtils.toString(response.getBody(), "UTF-8");
        final Model model = createDefaultModel().read(new ByteArrayInputStream(responseBody.getBytes()),
                null, config.getRdfLanguage());
        Set<URI> inboundMembers = null;

        if (!config.isIncludeBinaries() || config.retrieveInbound()) {

            if (!config.isIncludeBinaries()) {
                filterBinaryReferences(uri, model);
            }

            if (config.retrieveInbound()) {
                final URI subject = (binaryURI != null) ? binaryURI : uri;
                inboundMembers = filterInboundReferences(subject, model);
            }

            try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
                RDFDataMgr.write(out, model, contentTypeToLang(config.getRdfLanguage()));
                writeResponse(uri, new ByteArrayInputStream(out.toByteArray()), null, file);
            }
        } else {
            // we can write the body to disk unfiltered
            writeResponse(uri, new ByteArrayInputStream(responseBody.getBytes()), null, file);
        }

        //write headers file
        writeHeadersFile(response, getHeadersFile(file));

        exportLogger.info("export {} to {}", uri, file.getAbsolutePath());
        successCount.incrementAndGet();

        exportMembers(model, inboundMembers);
        exportVersions(uri);
    } catch ( Exception ex ) {
        ex.printStackTrace();
        exportLogger.error(String.format("Error exporting description: %1$s, Cause: %2$s",
                uri, ex.getMessage()), ex);
    }

}
 
Example 19
static public void serializeJenaCompositeEvents (OutputStream stream,
                                                 ArrayList<CompositeEvent> semEvents,
                                                 HashMap <String, SourceMeta> sourceMetaHashMap,
                                                 boolean ILIURI,
                                                 boolean VERBOSE_MENTIONS) {




    createModels();

    addJenaCompositeEvents(semEvents, sourceMetaHashMap, ILIURI, VERBOSE_MENTIONS);

    try {
        RDFDataMgr.write(stream, ds, RDFFormat.TRIG_PRETTY);
    } catch (Exception e) {
      //  e.printStackTrace();
    }


}
 
Example 20
/**
 * Given a Model, return the OWLOntology representation of the axioms.
 *
 * @deprecated Use {@link #convertModel(Model, IOHelper, String)}
 * @param model Model to convert to OWLOntology
 * @return OWLOntology of axioms
 * @throws OWLOntologyCreationException on issue loading ontology from byte array
 */
@Deprecated
public static OWLOntology convertModel(Model model) throws OWLOntologyCreationException {
  ByteArrayOutputStream os = new ByteArrayOutputStream();
  RDFDataMgr.write(os, model, Lang.TTL);
  OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
  return manager.loadOntologyFromOntologyDocument(new ByteArrayInputStream(os.toByteArray()));
}