Java Code Examples for org.apache.jena.riot.RDFDataMgr

The following examples show how to use org.apache.jena.riot.RDFDataMgr. 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: rmlmapper-java   Source File: Mapper_SPARQL_Test.java    License: MIT License 6 votes vote down vote up
private void mappingTest(String testCaseName, Class expectedException) throws Exception {
    String resourcePath = "test-cases/" + testCaseName + "-SPARQL/resource.ttl";
    String mappingPath = "./test-cases/" + testCaseName + "-SPARQL/mapping.ttl";
    String outputPath = "test-cases/" + testCaseName + "-SPARQL/output.nq";
    String tempMappingPath = replacePortInMappingFile(mappingPath, "" + PORTNUMBER_SPARQL);

    builder.add("/ds"+(1), RDFDataMgr.loadDataset(resourcePath), true);
    this.server = builder.build();
    this.server.start();

    // mapping
    if (expectedException == null) {
        doMapping(tempMappingPath, outputPath);
    } else {
        doMappingExpectError(tempMappingPath);
    }

    deleteTempMappingFile(tempMappingPath);
}
 
Example 2
public static void main(String[] args) throws IOException {

		File f = new File("/Users/rosenc/Documents/business/[2015]icbms/json_sample1.txt");
		BufferedReader br = new BufferedReader(new FileReader(f));
		String line = null;
		String s = "";
		while ((line = br.readLine()) != null) {
			s = s + line + "\n";
		}

		System.out.println(s);
		Gson gson = new Gson();
		OneM2MContentInstanceDTO cont = gson.fromJson(s, OneM2MContentInstanceDTO.class);
		OneM2MContentInstanceMapper mapper = new OneM2MContentInstanceMapper(cont);

		Model model = ModelFactory.createDefaultModel();
		model.add(mapper.from());
		System.out.println("content type ; " + mapper.getContentType());
		// 스트링 변환부분
		RDFDataMgr.write(System.out, model, RDFFormat.NTRIPLES);
		// System.out.println(mapper.getTypedContent("2k42kk"));
		// mapper.getTypedContent("2.4");

	}
 
Example 3
Source Project: NLIWOD   Source File: NtripleUtil.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
private static PipedRDFIterator<Triple> fileToStreamIterator(String filename) {
	PipedRDFIterator<Triple> iter = new PipedRDFIterator<>();
	final PipedRDFStream<Triple> inputStream = new PipedTriplesStream(iter);

	// PipedRDFStream and PipedRDFIterator need to be on different threads
	ExecutorService executor = Executors.newSingleThreadExecutor();

	// Create a runnable for our parser thread
	Runnable parser = new Runnable() {

		@Override
		public void run() {
			RDFDataMgr.parse(inputStream, filename);
		}
	};

	// Start the parser on another thread
	executor.submit(parser);
	// We will consume the input on the main thread here
	// We can now iterate over data as it is parsed, parsing only runs as
	// far ahead of our consumption as the buffer size allows
	return iter;
}
 
Example 4
Source Project: JedAIToolkit   Source File: GtRDFReader.java    License: Apache License 2.0 6 votes vote down vote up
protected void performReading() {
    final Model model = RDFDataMgr.loadModel(inputFilePath);
    final StmtIterator iter = model.listStatements();
    while (iter.hasNext()) {
        Statement stmt = iter.nextStatement();

        final String pred = stmt.getPredicate().toString();
        if (!(pred.contains("sameAs"))) {
            continue;
        }

        final String sub = stmt.getSubject().toString();
        final String obj = stmt.getObject().toString();

        // add a new edge for every pair of duplicate entities
        int entityId1 = urlToEntityId1.get(sub);
        int entityId2 = urlToEntityId1.get(obj) + datasetLimit;

        duplicatesGraph.addEdge(entityId1, entityId2);
    }
}
 
Example 5
Source Project: JedAIToolkit   Source File: EntityRDFReader.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public List<EntityProfile> getEntityProfiles() {
    if (!entityProfiles.isEmpty()) {
        return entityProfiles;
    }

    if (inputFilePath == null) {
        Log.error("Input file path has not been set!");
        return null;
    }

    //load the rdf model from the input file
    try {
        final Model model = RDFDataMgr.loadModel(inputFilePath);
        readModel(model);
    } catch (IOException ex) {
        Log.error("Error in entities reading!", ex);
        return null;
    }

    return entityProfiles;
}
 
Example 6
Source Project: xcurator   Source 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 7
Source Project: EventCoreference   Source File: JenaSerialization.java    License: Apache License 2.0 6 votes vote down vote up
static public void serializeJenaCompositeEvents (OutputStream stream,
                                                 HashMap<String, 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 8
Source Project: rdf-delta   Source File: DeltaEx01_DatasetWithPatchLog.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String ...args) {
    // -- Base dataset
    DatasetGraph dsgBase = DatasetGraphFactory.createTxnMem();

    // -- Destination for changes.
    // Text form of output.
    OutputStream out = System.out;
    // Create an RDFChanges that writes to "out".
    RDFChanges changeLog = RDFPatchOps.textWriter(out);

    // Combined datasetgraph and changes.
    DatasetGraph dsg = RDFPatchOps.changes(dsgBase, changeLog);

    // Wrap in the Dataset API
    Dataset ds = DatasetFactory.wrap(dsg);

    // --------
    // Do something. Read in data.ttl inside a transaction.
    // (data.ttl is in src/main/resources/)
    Txn.executeWrite(ds,
        ()->RDFDataMgr.read(dsg, "data.ttl")
        );
}
 
Example 9
Source Project: xcurator   Source 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 10
Source Project: incubator-taverna-language   Source File: RDFToManifest.java    License: Apache License 2.0 6 votes vote down vote up
protected static Model jsonLdAsJenaModel(InputStream jsonIn, URI base)
		throws IOException, RiotException {
	Model model = ModelFactory.createDefaultModel();

	ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
	try {
		// TAVERNA-971: set context classloader so jarcache.json is consulted
		// even through OSGi
		Thread.currentThread().setContextClassLoader(RDFToManifest.class.getClassLoader());

		// Now we can parse the JSON-LD without network access
		RDFDataMgr.read(model, jsonIn, base.toASCIIString(), Lang.JSONLD);
	} finally {
		// Restore old context class loader (if any)
		Thread.currentThread().setContextClassLoader(oldCl);
	}
	return model;
}
 
Example 11
private static void readTrigFromStream(Dataset ds, Dataset dsnew) {
    InputStream is = null;
    try {
        is = System.in;

        if (is==null){
            throw new IllegalArgumentException(
                    "No stream input!");
        }

        ByteArrayOutputStream b = cloneInputStream(is);
        InputStream is1 = new ByteArrayInputStream(b.toByteArray());
        InputStream is2 = new ByteArrayInputStream(b.toByteArray());

        RDFDataMgr.read(ds, is1, RDFLanguages.TRIG);
        RDFDataMgr.read(dsnew, is2, RDFLanguages.TRIG);

    }
    finally {
        // close the streams using close method

    }

}
 
Example 12
Source Project: xcurator   Source File: ExRIOT_1.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String...argv)
{
    Model m = ModelFactory.createDefaultModel() ;
    // read into the model.
    m.read("data.ttl") ;
    
    // Alternatively, use the RDFDataMgr, which reads from the web,
    // with content negotiation.  Plain names are assumed to be 
    // local files where file extension indicates the syntax.  
    
    Model m2 = RDFDataMgr.loadModel("data.ttl") ;
    
    // read in more data, the remote server serves up the data
    // with the right MIME type.
    RDFDataMgr.read(m2, "http://host/some-published-data") ;
    
    
    // Read some data but also give a hint for the synatx if it is not
    // discovered by inspectying the file or by HTTP content negotiation.  
    RDFDataMgr.read(m2, "some-more-data.out", RDFLanguages.TURTLE) ;
}
 
Example 13
Source Project: xcurator   Source File: ExRIOT_3.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String...argv)
{
    Dataset ds = null ;
    
    // Read a TriG file into quad storage in-memory.
    ds = RDFDataMgr.loadDataset("data.trig") ;
    
    // read some (more) data into a dataset graph.
    RDFDataMgr.read(ds, "data2.trig") ;
    
    // Create a dataset,
    Dataset ds2 = DatasetFactory.createTxnMem() ;
    // read in data, indicating the syntax in case the remote end does not
    // correctly provide the HTTP content type.
    RDFDataMgr.read(ds2, "http://host/data2.unknown", TRIG) ;
}
 
Example 14
Source Project: EventCoreference   Source File: GetPerspectiveRelations.java    License: Apache License 2.0 6 votes vote down vote up
public static void perspectiveRelationsToTrig (String pathToTrigFile, ArrayList<PerspectiveObject> perspectiveObjects) {
    try {
        OutputStream fos = new FileOutputStream(pathToTrigFile);
        Dataset ds = TDBFactory.createDataset();
        Model defaultModel = ds.getDefaultModel();
        //ResourcesUri.prefixModel(defaultModel);
      //  Model provenanceModel = ds.getNamedModel("http://www.newsreader-project.eu/perspective");
        ResourcesUri.prefixModelGaf(defaultModel);
        String attrBase = pathToTrigFile+"_";
        JenaSerialization.addJenaPerspectiveObjects(attrBase, ResourcesUri.grasp, "wasAttributedTo", perspectiveObjects, 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 15
Source Project: SolRDF   Source File: IntegrationTestSupertypeLayer.java    License: Apache License 2.0 6 votes vote down vote up
protected void assertIsomorphic(final Model memoryModel, final Model solrdfModel, final String uri) {
	try {
		assertTrue(solrdfModel.isIsomorphicWith(memoryModel));
	} catch (Throwable exception) {
		final StringWriter memoryModelWriter = new StringWriter();
		final StringWriter remoteModelWriter = new StringWriter();
		RDFDataMgr.write(memoryModelWriter, memoryModel, RDFFormat.NTRIPLES) ;
		RDFDataMgr.write(remoteModelWriter, solrdfModel, RDFFormat.NQUADS) ;

		final String name = uri != null ? uri : " (DEFAULT) ";
		log.debug("**** MEMORY MODEL " + name + " ****");
		log.debug(memoryModelWriter.toString());
		log.debug("");
		log.debug("**** REMOTE MODEL " + name + " ****");
		log.debug(remoteModelWriter.toString());
		log.debug("*********************************");
		throw exception;
	}
}
 
Example 16
Source Project: IGUANA   Source File: Stresstest.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void init(String host, String queueName) throws IOException, TimeoutException {
	super.init(host, queueName);

	// create from construct args and class
	QueryHandlerFactory factory = new QueryHandlerFactory();
	// add Worker
	QueryHandler queryHandler = factory.createWorkerBasedQueryHandler(qhClassName, qhConstructorArgs, workers);
	queryHandler.generateQueries();

       Model tripleStats = queryHandler.generateTripleStats(taskID, iguanaResource, iguanaProperty);
	StringWriter sw = new StringWriter();
	RDFDataMgr.write(sw, tripleStats, RDFFormat.NTRIPLES);
	this.metaData.put(COMMON.SIMPLE_TRIPLE_KEY, sw.toString());
	this.metaData.put(COMMON.QUERY_STATS, tripleStats);


}
 
Example 17
Source Project: RDFstarTools   Source File: QueryExecutionTest.java    License: Apache License 2.0 5 votes vote down vote up
protected Model loadModel( String filename )
{
	final String fullFilename = getClass().getResource("/TurtleStar/"+filename).getFile();

	final Graph g = new GraphWrapperStar( GraphFactory.createDefaultGraph() );
	final Model m = ModelFactory.createModelForGraph(g);
	RDFDataMgr.read(m, fullFilename);
	return m;
}
 
Example 18
Source Project: RDFstarTools   Source File: QueryExecutionTest.java    License: Apache License 2.0 5 votes vote down vote up
protected Dataset loadDataset( String filename )
{
	final String fullFilename = getClass().getResource("/TurtleStar/"+filename).getFile();

	final DatasetGraph dsg = DatasetGraphFactory.createTxnMem();
   	final DatasetGraph dsgWrapped = new DatasetGraphWrapperStar(dsg);
   	final Dataset ds = DatasetFactory.wrap(dsgWrapped);
	RDFDataMgr.read(ds, fullFilename);
	return ds;
}
 
Example 19
Source Project: trellis   Source 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 20
Source Project: trellis   Source File: JenaIOServiceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void testNTriplesSerializer() {
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    service3.write(getTriples(), out, NTRIPLES, identifier);
    final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    final org.apache.jena.graph.Graph graph = createDefaultGraph();
    RDFDataMgr.read(graph, in, Lang.NTRIPLES);
    assertTrue(validateGraph(fromJena(graph)), "Failed round-trip for N-Triples!");
}
 
Example 21
Source Project: trellis   Source File: JenaIOServiceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void testBufferedSerializer() {
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    service.write(getTriples(), out, RDFXML, identifier);
    final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    final org.apache.jena.graph.Graph graph = createDefaultGraph();
    RDFDataMgr.read(graph, in, Lang.RDFXML);
    assertTrue(validateGraph(fromJena(graph)), "Failed round-trip for RDFXML!");
}
 
Example 22
Source Project: trellis   Source File: JenaIOServiceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void testTurtleSerializer() {
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    service.write(getTriples(), out, TURTLE, identifier);
    final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    final org.apache.jena.graph.Graph graph = createDefaultGraph();
    RDFDataMgr.read(graph, in, Lang.TURTLE);
    assertTrue(validateGraph(fromJena(graph)), "Failed round-trip for Turtle!");
}
 
Example 23
Source Project: trellis   Source File: JenaIOServiceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void testNullHtmlSerializer() {
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    service.write(getTriples(), out, RDFA, identifier);
    final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    final org.apache.jena.graph.Graph graph = createDefaultGraph();
    RDFDataMgr.read(graph, in, Lang.TURTLE);
    assertTrue(validateGraph(fromJena(graph)), "null HTML serialization didn't default to Turtle!");
}
 
Example 24
Source Project: SDA   Source 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 25
Source Project: SDA   Source File: OneM2MContainerDTO.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void main(String[] args) {
		String sample = "{     \"_id\" : ObjectId(\"561f27831ee8202c5e307d37\"),     \"rn\" : \"CONTAINER_268\",     \"ty\" : 3,     \"ri\" : \"CONTAINER_268\",     \"pi\" : \"SAE_0\",     \"lbl\" : [          \"switch\",          \"key1\",          \"key2\"     ],     \"et\" : \"20151203T122321\",     \"cr\" : \"//onem2m.herit.net/herit-cse/SAE_5\",     \"mni\" : 100,     \"mbs\" : 1.024e+006,     \"mia\" : 36000,     \"cni\" : 1,     \"cbs\" : 2,     \"_uri\" : \"/herit-in/herit-cse/SAE_0/CONTAINER_268\",     \"ct\" : \"20151015T131147\",     \"lt\" : \"20151015T131147\", \"or\":\"http://www.pineone.com/m2m/SwitchStatusSensor\" }";
		Gson gson = new Gson();
		OneM2MContainerDTO cont = gson.fromJson(sample, OneM2MContainerDTO.class);


		System.out.println(cont);
		
		OneM2MContainerMapper mapper = new OneM2MContainerMapper(cont);
		Model model = ModelFactory.createDefaultModel();
		model.add(mapper.from());
		
		//스트링 변환부분
		RDFDataMgr.write(System.out, model, RDFFormat.NTRIPLES);

		//스트링 변환부분
//		String serviceURI = "http://219.248.137.7:13030/icbms";
//
//		DatasetAccessor	accessor = DatasetAccessorFactory.createHTTP(serviceURI);
//		accessor.deleteDefault();
//		accessor.add(model);
//		
//		
//		QueryExecution q = QueryExecutionFactory.sparqlService(serviceURI	,"select * {?s ?p ?o}"	);
//		ResultSet rs = q.execSelect();
//		ResultSetFormatter.out(rs);;
		
//		model = DatasetAccessorFactory.createHTTP(serviceURI).getModel();
//		System.out.println(model.size());

	}
 
Example 26
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 27
Source Project: SDA   Source File: OneM2MCSEBaseDTO.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 28
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 29
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 30
Source Project: fcrepo-import-export   Source File: Importer.java    License: Apache License 2.0 5 votes vote down vote up
private Model parseStream(final InputStream in) throws IOException {
    final SubjectMappingStreamRDF mapper = new SubjectMappingStreamRDF(config.getSource(),
                                                                       config.getDestination());
    try (final InputStream in2 = in) {
        RDFDataMgr.parse(mapper, in2, contentTypeToLang(config.getRdfLanguage()));
    }
    return mapper.getModel();
}