org.apache.jena.riot.RDFFormat Java Examples
The following examples show how to use
org.apache.jena.riot.RDFFormat.
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 File: JenaIOService.java From trellis with Apache License 2.0 | 6 votes |
private void writeJsonLd(final OutputStream output, final DatasetGraph graph, final IRI... profiles) { final String profile = getCustomJsonLdProfile(profiles); final RDFFormat format = canUseCustomJsonLdProfile(profile) ? JSONLD_COMPACT_FLAT : getJsonLdProfile(profiles); final JsonLDWriteContext ctx = new JsonLDWriteContext(); if (canUseCustomJsonLdProfile(profile)) { LOGGER.debug("Setting JSON-LD context with profile: {}", profile); final String c = cache.get(profile, p -> { try (final TypedInputStream res = HttpOp.execHttpGet(profile)) { return IOUtils.toString(res.getInputStream(), UTF_8); } catch (final IOException | HttpException ex) { LOGGER.warn("Error fetching profile {}: {}", p, ex.getMessage()); return null; } }); if (c != null) { ctx.setJsonLDContext(c); ctx.setJsonLDContextSubstitution("\"" + profile + "\""); } } RDFWriter.create().format(format).context(ctx).source(graph).output(output); }
Example #2
Source File: JenaSerialization.java From EventCoreference with Apache License 2.0 | 6 votes |
static public void serializeJenaSingleCompositeEvents (OutputStream stream, HashMap<String, CompositeEvent> semEvents, HashMap <String, SourceMeta> sourceMetaHashMap, boolean ILIURI, boolean VERBOSE_MENTIONS) { createModels(); Set keySet = semEvents.keySet(); Iterator<String> keys = keySet.iterator(); while (keys.hasNext()) { String key = keys.next(); if (DEBUG) System.out.println("key = " + key); CompositeEvent semEvent = semEvents.get(key); if (semEvent!=null) { addJenaCompositeEvent(semEvent, sourceMetaHashMap, ILIURI, VERBOSE_MENTIONS); } } try { RDFDataMgr.write(stream, ds, RDFFormat.TRIG_PRETTY); } catch (Exception e) { // e.printStackTrace(); } }
Example #3
Source File: JenaSerialization.java From EventCoreference with Apache License 2.0 | 6 votes |
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 #4
Source File: GetPerspectiveRelations.java From EventCoreference with Apache License 2.0 | 6 votes |
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 #5
Source File: OneM2MContentInstanceMapper.java From SDA with BSD 2-Clause "Simplified" License | 6 votes |
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 #6
Source File: Stresstest.java From IGUANA with GNU Affero General Public License v3.0 | 6 votes |
@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 #7
Source File: IntegrationTestSupertypeLayer.java From SolRDF with Apache License 2.0 | 6 votes |
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 #8
Source File: OneM2MContentInstanceMapper.java From SDA with BSD 2-Clause "Simplified" License | 6 votes |
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 #9
Source File: WriteStatementsKnowledgeStore.java From EventCoreference with Apache License 2.0 | 5 votes |
static public void main (String[] args) { Dataset dataset = null; String address = "http://145.100.57.176:50053/"; ArrayList<org.openrdf.model.Statement> statements = new ArrayList<org.openrdf.model.Statement>(); Iterator<String> it = dataset.listNames(); while (it.hasNext()) { String name = it.next(); Model namedModel = dataset.getNamedModel(name); StmtIterator siter = namedModel.listStatements(); while (siter.hasNext()) { com.hp.hpl.jena.rdf.model.Statement s = siter.nextStatement(); org.openrdf.model.Statement statement =castJenaOpenRdf(s, name); if (statement!=null) { statements.add(statement); } } } if (DEBUG) { try { ByteArrayOutputStream os = new ByteArrayOutputStream(); RDFDataMgr.write(os, dataset, RDFFormat.TRIG_PRETTY); String rdfString = new String(os.toByteArray(), "UTF-8"); System.out.println("rdfString = " + rdfString); os.close(); } catch (Exception e) { e.printStackTrace(); } } // System.out.println("address = " + address); WriteStatementsKnowledgeStore.storeTriples(statements, address); }
Example #10
Source File: JenaSerialization.java From EventCoreference with Apache License 2.0 | 5 votes |
static public void serializeJenaCompositeEventsAndPerspective (OutputStream stream, ArrayList<CompositeEvent> semEvents, KafSaxParser kafSaxParser, String project, ArrayList<PerspectiveObject> sourcePerspectiveObjects, ArrayList<PerspectiveObject> authorPerspectiveObjects) { createModels(); addJenaCompositeEvents(semEvents, null, false, false); String docId = kafSaxParser.getKafMetaData().getUrl().replaceAll("#", "HASH"); if (!docId.toLowerCase().startsWith("http")) { docId = ResourcesUri.nwrdata + project + "/" + docId; } // System.err.println("docId = " + docId); // System.err.println("kafSaxParser = " + kafSaxParser.getKafMetaData().getUrl()); addDocMetaData(docId, kafSaxParser, project); String attrBase = docId+"/"+"source_attribution/"; addJenaPerspectiveObjects(attrBase, ResourcesUri.grasp, "wasAttributedTo",sourcePerspectiveObjects, 1); attrBase = docId+"/"+"doc_attribution/"; addJenaPerspectiveObjects(attrBase, ResourcesUri.prov, "wasDerivedFrom", authorPerspectiveObjects, sourcePerspectiveObjects.size()+1); try { RDFDataMgr.write(stream, ds, RDFFormat.TRIG_PRETTY); } catch (Exception e) { // e.printStackTrace(); } }
Example #11
Source File: GetPerspectiveRelations.java From EventCoreference with Apache License 2.0 | 5 votes |
public static void perspectiveRelationsToTrigStream (OutputStream fos, String uri, ArrayList<PerspectiveObject> perspectiveObjects) { 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 = uri+"_"; JenaSerialization.addJenaPerspectiveObjects(attrBase, ResourcesUri.grasp,"wasAttributedTo", perspectiveObjects, 1); RDFDataMgr.write(fos, ds, RDFFormat.TRIG_PRETTY); }
Example #12
Source File: GetPerspectiveRelations.java From EventCoreference with Apache License 2.0 | 5 votes |
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 #13
Source File: NTFileStorage.java From IGUANA with GNU Affero General Public License v3.0 | 5 votes |
@Override public void commit() { try (OutputStream os = new FileOutputStream(file.toString())) { RDFDataMgr.write(os, metricResults, RDFFormat.NTRIPLES); } catch (IOException e) { LOGGER.error("Could not commit to NTFileStorage.", e); } }
Example #14
Source File: IntegrationTestSupertypeLayer.java From SolRDF with Apache License 2.0 | 5 votes |
/** * 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 #15
Source File: IntegrationTestSupertypeLayer.java From SolRDF with Apache License 2.0 | 5 votes |
/** * 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 #16
Source File: SHACLC.java From shacl with Apache License 2.0 | 5 votes |
public static void install() { RDFLanguages.register(SHACLC.lang); RDFParserRegistry.registerLangTriples(SHACLC.lang, (language, profile) -> new SHACLCReader()); RDFFormat format = new RDFFormat(SHACLC.lang); RDFWriterRegistry.register(SHACLC.lang, format); RDFWriterRegistry.register(format, new WriterGraphRIOTFactory() { @Override public WriterGraphRIOT create(RDFFormat syntaxForm) { return new SHACLCWriter(); } }); // new SHACLCTestRunner().run(); }
Example #17
Source File: OneM2MContentInstanceDTO.java From SDA with BSD 2-Clause "Simplified" License | 5 votes |
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 #18
Source File: OneM2MAEDTO.java From SDA with BSD 2-Clause "Simplified" License | 5 votes |
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 #19
Source File: OneM2MContainerDTO.java From SDA with BSD 2-Clause "Simplified" License | 5 votes |
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 #20
Source File: OneM2MContentInstanceDTO.java From SDA with BSD 2-Clause "Simplified" License | 5 votes |
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 #21
Source File: OneM2MCSEBaseDTO.java From SDA with BSD 2-Clause "Simplified" License | 5 votes |
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 #22
Source File: PropertySurfaceForms.java From NLIWOD with GNU Affero General Public License v3.0 | 5 votes |
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 #23
Source File: ClassSurfaceForms.java From NLIWOD with GNU Affero General Public License v3.0 | 5 votes |
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 #24
Source File: OneM2MAEDTO.java From SDA with BSD 2-Clause "Simplified" License | 5 votes |
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 File: OneM2MContainerDTO.java From SDA with BSD 2-Clause "Simplified" License | 5 votes |
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
Source File: OneM2MCSEBaseDTO.java From SDA with BSD 2-Clause "Simplified" License | 5 votes |
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 #27
Source File: TripleService.java From SDA with BSD 2-Clause "Simplified" License | 4 votes |
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) { // ty값을 확인하기 위해서 특정 객체에 매핑해봄(ty=4) 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); } log.debug("=== ri : "+contextInstanceDTO.getRi()+", ty : "+ty+" ====>include"); OneM2MContentInstanceMapper mapper = new OneM2MContentInstanceMapper(contextInstanceDTO); Model model = ModelFactory.createDefaultModel(); model.add(mapper.from()); // 스트링 변환부분(test) //RDFDataMgr.write(System.out, model, RDFFormat.NTRIPLES); // 스트링 변환부분 RDFDataMgr.write(sw, model, RDFFormat.NTRIPLES); returnStr = sw.toString(); sw.flush(); } else if (ty == 3) { log.debug("=== ri: "+ri+", ty : "+ty+" ====>exclude"); sw.flush(); /* * OneM2MContainerDTO cont = null; if (doc instanceof DBObject) { * gson.toJson(doc)); cont = gson.fromJson(gson.toJson(doc), * OneM2MContainerDTO.class); } else if (doc instanceof String) { * (doc)); cont = gson.fromJson((String) doc, * OneM2MContainerDTO.class); } OneM2MContainerMapper mapper = new * OneM2MContainerMapper(cont); Model model = * ModelFactory.createDefaultModel(); model.add(mapper.from()); * * // 스트링 변환부분 RDFDataMgr.write(sw, model, RDFFormat.NTRIPLES); * * log.debug("value from mongo ====3(json)====>" + * cont.toString()); log.debug( * "value from mongo ====3(sw)====>" + sw.toString()); * * returnStr = sw.toString(); sw.flush(); */ } else if (ty == 2) { log.debug("=== ri : "+ri+", ty : "+ty+" ====>exclude"); sw.flush(); /* * OneM2MAEDTO cont = null; if (doc instanceof DBObject) { * gson.toJson(doc)); cont = gson.fromJson(gson.toJson(doc), * OneM2MAEDTO.class); } else if (doc instanceof String) { * (doc)); cont = gson.fromJson((String) (doc), OneM2MAEDTO.class); * } OneM2MAEMapper mapper = new OneM2MAEMapper(cont); * * Model model = ModelFactory.createDefaultModel(); * model.add(mapper.from()); * * // 스트링 변환부분 RDFDataMgr.write(sw, model, RDFFormat.NTRIPLES); * * log.debug("value from mongo ====2(json)====>" + * cont.toString()); log.debug( * "value from mongo ====2(sw)====>" + sw.toString()); * * returnStr = sw.toString(); 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 #28
Source File: TripleService.java From SDA with BSD 2-Clause "Simplified" License | 4 votes |
/** * 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 #29
Source File: TripleService.java From SDA with BSD 2-Clause "Simplified" License | 4 votes |
/** * 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 #30
Source File: JenaSerialization.java From EventCoreference with Apache License 2.0 | 4 votes |
static public void serializeJena (OutputStream stream, ArrayList<SemObject> semEvents, ArrayList<SemObject> semActors, ArrayList<SemTime> semTimes, ArrayList<SemRelation> semRelations, HashMap<String, SourceMeta> sourceMetaHashMap, boolean ILIURI, boolean VERBOSE_MENTIONS) { // create an empty Model createModels(); // System.out.println("EVENTS"); for (int i = 0; i < semEvents.size(); i++) { SemObject semEvent = semEvents.get(i); //semEvent.addToJenaModel(instanceModel, Sem.Event); semEvent.addToJenaModel(instanceModel, Sem.Event, VERBOSE_MENTIONS); } // System.out.println("ACTORS"); for (int i = 0; i < semActors.size(); i++) { SemObject semActor = semActors.get(i); // semActor.addToJenaModel(instanceModel, Sem.Actor); semActor.addToJenaModel(instanceModel, Sem.Actor, VERBOSE_MENTIONS); } // System.out.println("TIMES"); for (int i = 0; i < semTimes.size(); i++) { SemTime semTime = (SemTime) semTimes.get(i); if (semTime.getType().equalsIgnoreCase(TimeTypes.YEAR)) { semTime.addToJenaModelDocTimeInstant(instanceModel); //OR // semTime.addToJenaModelTimeIntervalCondensed(instanceModel); } else if (semTime.getType().equalsIgnoreCase(TimeTypes.QUARTER)) { semTime.addToJenaModelTimeIntervalCondensed(instanceModel); } else if (semTime.getType().equalsIgnoreCase(TimeTypes.MONTH)) { semTime.addToJenaModelDocTimeInstant(instanceModel); //OR // semTime.addToJenaModelTimeIntervalCondensed(instanceModel); } else if (semTime.getType().equalsIgnoreCase(TimeTypes.DURATION)) { semTime.addToJenaModelTimeIntervalCondensed(instanceModel); } else { /// DATE semTime.addToJenaModelDocTimeInstant(instanceModel); } } //System.out.println("RELATIONS"); for (int i = 0; i < semRelations.size(); i++) { SemRelation semRelation = semRelations.get(i); if (sourceMetaHashMap!=null) { semRelation.addToJenaDataSet(ds, provenanceModel, sourceMetaHashMap); } else { semRelation.addToJenaDataSet(ds, provenanceModel); } ///** Next version adds relations to one single relation graph //semRelation.addToJenaDataSet(ds, relationModel, provenanceModel); } RDFDataMgr.write(stream, ds, RDFFormat.TRIG_PRETTY); // RDFDataMgr.write(stream, ds, RDFFormat.RDFJSON); // RDFWriter writer = ds.getDefaultModel().getWriter(); // writer.write(ds.getDefaultModel(), stream, RDFFormat.RDFJSON); // writer.write(ds.getDefaultModel(), ); // defaultModel.write(stream); }