Java Code Examples for com.hp.hpl.jena.rdf.model.ModelFactory#createDefaultModel()

The following examples show how to use com.hp.hpl.jena.rdf.model.ModelFactory#createDefaultModel() . 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: CQELSAarhusPollutionStream.java    From Benchmark with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected List<Statement> getStatements(SensorObservation so) {
	Model m = ModelFactory.createDefaultModel();
	if (ed != null)
		for (String s : ed.getPayloads()) {
			Resource observation = m
					.createResource(RDFFileManager.defaultPrefix + so.getObId() + UUID.randomUUID());
			// so.setObId(RDFFileManager.defaultPrefix + observation.toString());
			CityBench.obMap.put(observation.toString(), so);
			observation.addProperty(RDF.type, m.createResource(RDFFileManager.ssnPrefix + "Observation"));

			Resource serviceID = m.createResource(ed.getServiceId());
			observation.addProperty(m.createProperty(RDFFileManager.ssnPrefix + "observedBy"), serviceID);
			observation.addProperty(m.createProperty(RDFFileManager.ssnPrefix + "observedProperty"),
					m.createResource(s.split("\\|")[2]));
			Property hasValue = m.createProperty(RDFFileManager.saoPrefix + "hasValue");
			observation.addLiteral(hasValue, ((PollutionObservation) so).getApi());
		}
	return m.listStatements().toList();
}
 
Example 2
Source File: DataWrapper.java    From Benchmark with GNU General Public License v3.0 6 votes vote down vote up
public static List<Statement> getAarhusWeatherStatements(SensorObservation wo, EventDeclaration ed) {
	Model m = ModelFactory.createDefaultModel();
	if (ed != null)
		for (String s : ed.getPayloads()) {
			Resource observation = m
					.createResource(RDFFileManager.defaultPrefix + wo.getObId() + UUID.randomUUID());
			// wo.setObId(observation.toString());
			CityBench.obMap.put(observation.toString(), wo);
			observation.addProperty(RDF.type, m.createResource(RDFFileManager.ssnPrefix + "Observation"));
			Resource serviceID = m.createResource(ed.getServiceId());
			observation.addProperty(m.createProperty(RDFFileManager.ssnPrefix + "observedBy"), serviceID);
			observation.addProperty(m.createProperty(RDFFileManager.ssnPrefix + "observedProperty"),
					m.createResource(s.split("\\|")[2]));
			Property hasValue = m.createProperty(RDFFileManager.saoPrefix + "hasValue");
			if (s.contains("Temperature"))
				observation.addLiteral(hasValue, ((WeatherObservation) wo).getTemperature());
			else if (s.toString().contains("Humidity"))
				observation.addLiteral(hasValue, ((WeatherObservation) wo).getHumidity());
			else if (s.toString().contains("WindSpeed"))
				observation.addLiteral(hasValue, ((WeatherObservation) wo).getWindSpeed());
		}
	return m.listStatements().toList();
}
 
Example 3
Source File: ResourceBuilder.java    From LodView with MIT License 6 votes vote down vote up
public String buildRDFResource(String IRI, Model m, Lang lang, ConfigurationBean conf) throws Exception {
	String result = "empty content";
	Model model = ModelFactory.createDefaultModel();
	model.setNsPrefixes(conf.getPrefixes());

	SPARQLEndPoint se = new SPARQLEndPoint(conf, null, null);
	model = se.extractLocalData(model, IRI, m, conf.getDefaultRawDataQueries());

	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	RDFWriter rdfWriter = model.getWriter(lang.getName());
	rdfWriter.setProperty("showXMLDeclaration","true");
	rdfWriter.setProperty("relativeURIs","");

	rdfWriter.write(model, baos, conf.getIRInamespace());
	rdfWriter.setProperty("showXMLDeclaration","true");
	rdfWriter.setProperty("relativeURIs","");

	byte[] resultByteArray = baos.toByteArray();
	result = new String(resultByteArray);

	return result;
}
 
Example 4
Source File: CSPARQLAarhusWeatherStream.java    From Benchmark with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected List<Statement> getStatements(SensorObservation wo) throws NumberFormatException, IOException {
	Model m = ModelFactory.createDefaultModel();
	if (ed != null)
		for (String s : ed.getPayloads()) {
			Resource observation = m
					.createResource(RDFFileManager.defaultPrefix + wo.getObId() + UUID.randomUUID());
			// wo.setObId(observation.toString());
			CityBench.obMap.put(observation.toString(), wo);
			observation.addProperty(RDF.type, m.createResource(RDFFileManager.ssnPrefix + "Observation"));
			Resource serviceID = m.createResource(ed.getServiceId());
			observation.addProperty(m.createProperty(RDFFileManager.ssnPrefix + "observedBy"), serviceID);
			observation.addProperty(m.createProperty(RDFFileManager.ssnPrefix + "observedProperty"),
					m.createResource(s.split("\\|")[2]));
			Property hasValue = m.createProperty(RDFFileManager.saoPrefix + "hasValue");
			if (s.contains("Temperature"))
				observation.addLiteral(hasValue, ((WeatherObservation) wo).getTemperature());
			else if (s.toString().contains("Humidity"))
				observation.addLiteral(hasValue, ((WeatherObservation) wo).getHumidity());
			else if (s.toString().contains("WindSpeed"))
				observation.addLiteral(hasValue, ((WeatherObservation) wo).getWindSpeed());
		}
	return m.listStatements().toList();
}
 
Example 5
Source File: OntologyHandler.java    From dbpedia-live-mirror with GNU General Public License v3.0 6 votes vote down vote up
private List<String> getRemoteOntologyTriples() {
    List<String> triples = null;

    try (
            final ByteArrayOutputStream os = new ByteArrayOutputStream();
    ){
        Model model = ModelFactory.createDefaultModel();
        model.read(ontologyURI);

        model.write(os, "N-TRIPLE");

        String ontology = os.toString("UTF8");

        triples = new ArrayList<>();
        for (String t : ontology.split("\n")) {
            triples.add(t.trim());
        }
        Collections.sort(triples);

    } catch (Exception e) {
        logger.warn("Cannot download remote ontology", e);
    } finally {
        return triples;
    }
}
 
Example 6
Source File: CSPARQLAarhusPollutionStream.java    From Benchmark with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected List<Statement> getStatements(SensorObservation so) {
	Model m = ModelFactory.createDefaultModel();
	if (ed != null)
		for (String s : ed.getPayloads()) {
			Resource observation = m
					.createResource(RDFFileManager.defaultPrefix + so.getObId() + UUID.randomUUID());
			// so.setObId(RDFFileManager.defaultPrefix + observation.toString());
			CityBench.obMap.put(observation.toString(), so);
			observation.addProperty(RDF.type, m.createResource(RDFFileManager.ssnPrefix + "Observation"));

			Resource serviceID = m.createResource(ed.getServiceId());
			observation.addProperty(m.createProperty(RDFFileManager.ssnPrefix + "observedBy"), serviceID);
			observation.addProperty(m.createProperty(RDFFileManager.ssnPrefix + "observedProperty"),
					m.createResource(s.split("\\|")[2]));
			Property hasValue = m.createProperty(RDFFileManager.saoPrefix + "hasValue");
			observation.addLiteral(hasValue, ((PollutionObservation) so).getApi());
		}
	return m.listStatements().toList();
}
 
Example 7
Source File: CSPARQLAarhusTrafficStream.java    From Benchmark with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected List<Statement> getStatements(SensorObservation data) throws NumberFormatException, IOException {
	// return DataWrapper.getAarhusTrafficStatements((AarhusTrafficObservation) data, ed);
	Model m = ModelFactory.createDefaultModel();
	if (ed != null)
		for (String pStr : ed.getPayloads()) {
			// if (s.contains("EstimatedTime")) {
			// Resource observedProperty = m.createResource(s);
			String obId = data.getObId();
			Resource observation = m.createResource(RDFFileManager.defaultPrefix + obId + UUID.randomUUID());
			CityBench.obMap.put(observation.toString(), data);
			// data.setObId(observation.toString());
			// System.out.println("OB: " + observation.toString());
			observation.addProperty(RDF.type, m.createResource(RDFFileManager.ssnPrefix + "Observation"));

			Resource serviceID = m.createResource(ed.getServiceId());
			observation.addProperty(m.createProperty(RDFFileManager.ssnPrefix + "observedBy"), serviceID);
			observation.addProperty(m.createProperty(RDFFileManager.ssnPrefix + "observedProperty"),
					m.createResource(pStr.split("\\|")[2]));
			Property hasValue = m.createProperty(RDFFileManager.saoPrefix + "hasValue");
			// System.out.println("Annotating: " + observedProperty.toString());
			if (pStr.contains("AvgSpeed"))
				observation.addLiteral(hasValue, ((AarhusTrafficObservation) data).getAverageSpeed());
			else if (pStr.contains("VehicleCount")) {
				double value = ((AarhusTrafficObservation) data).getVehicle_count();
				observation.addLiteral(hasValue, value);
			} else if (pStr.contains("MeasuredTime"))
				observation.addLiteral(hasValue, ((AarhusTrafficObservation) data).getAvgMeasuredTime());
			else if (pStr.contains("EstimatedTime"))
				observation.addLiteral(hasValue, ((AarhusTrafficObservation) data).getEstimatedTime());
			else if (pStr.contains("CongestionLevel"))
				observation.addLiteral(hasValue, ((AarhusTrafficObservation) data).getCongestionLevel());
			// break;
			// }
		}
	return m.listStatements().toList();
}
 
Example 8
Source File: SimpleRDFJsonLDImport.java    From wandora with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void importRDF(InputStream in, TopicMap map) {
    if(in != null) {
        // create an empty model
        Model model = ModelFactory.createDefaultModel();
        // read the RDF json-ld file
        model.read(in, "", "JSON-LD");
        RDF2TopicMap(model, map);
    }
}
 
Example 9
Source File: CQELSAarhusTrafficStream.java    From Benchmark with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected List<Statement> getStatements(SensorObservation data) throws NumberFormatException, IOException {
	// return DataWrapper.getAarhusTrafficStatements((AarhusTrafficObservation) data, ed);
	Model m = ModelFactory.createDefaultModel();
	if (ed != null)
		for (String pStr : ed.getPayloads()) {
			// if (s.contains("EstimatedTime")) {
			// Resource observedProperty = m.createResource(s);
			data = (AarhusTrafficObservation) data;
			String obId = data.getObId();
			Resource observation = m.createResource(RDFFileManager.defaultPrefix + obId + UUID.randomUUID());
			CityBench.obMap.put(observation.toString(), data);
			// data.setObId(observation.toString());
			// System.out.println("OB: " + observation.toString());
			observation.addProperty(RDF.type, m.createResource(RDFFileManager.ssnPrefix + "Observation"));

			Resource serviceID = m.createResource(ed.getServiceId());
			observation.addProperty(m.createProperty(RDFFileManager.ssnPrefix + "observedBy"), serviceID);
			observation.addProperty(m.createProperty(RDFFileManager.ssnPrefix + "observedProperty"),
					m.createResource(pStr.split("\\|")[2]));
			Property hasValue = m.createProperty(RDFFileManager.saoPrefix + "hasValue");
			// System.out.println("Annotating: " + observedProperty.toString());
			if (pStr.contains("AvgSpeed"))
				observation.addLiteral(hasValue, ((AarhusTrafficObservation) data).getAverageSpeed());
			else if (pStr.contains("VehicleCount")) {
				double value = ((AarhusTrafficObservation) data).getVehicle_count();
				observation.addLiteral(hasValue, value);
			} else if (pStr.contains("MeasuredTime"))
				observation.addLiteral(hasValue, ((AarhusTrafficObservation) data).getAvgMeasuredTime());
			else if (pStr.contains("EstimatedTime"))
				observation.addLiteral(hasValue, ((AarhusTrafficObservation) data).getEstimatedTime());
			else if (pStr.contains("CongestionLevel"))
				observation.addLiteral(hasValue, ((AarhusTrafficObservation) data).getCongestionLevel());
			// break;
			// }
		}
	return m.listStatements().toList();
}
 
Example 10
Source File: DataWrapper.java    From Benchmark with GNU General Public License v3.0 5 votes vote down vote up
public static List<Statement> getUserLocationStatements(SensorObservation so, EventDeclaration ed) {
	String userStr = so.getFoi();
	String coordinatesStr = so.getValue().toString();
	Model m = ModelFactory.createDefaultModel();
	double lat = Double.parseDouble(coordinatesStr.split(",")[0]);
	double lon = Double.parseDouble(coordinatesStr.split(",")[1]);
	Resource serviceID = m.createResource(ed.getServiceId());
	//
	// Resource user = m.createResource(userStr);

	Resource observation = m.createResource(RDFFileManager.defaultPrefix + so.getObId() + UUID.randomUUID());
	CityBench.obMap.put(observation.toString(), so);
	observation.addProperty(RDF.type, m.createResource(RDFFileManager.ssnPrefix + "Observation"));
	// observation.addProperty(RDF.type, m.createResource(RDFFileManager.saoPrefix + "StreamData"));

	// location.addProperty(RDF.type, m.createResource(RDFFileManager.ctPrefix + "Location"));

	Resource coordinates = m.createResource();
	coordinates.addLiteral(m.createProperty(RDFFileManager.ctPrefix + "hasLatitude"), lat);
	coordinates.addLiteral(m.createProperty(RDFFileManager.ctPrefix + "hasLongitude"), lon);

	// observation.addProperty(m.createProperty(RDFFileManager.ssnPrefix + "featureOfInterest"), user);
	observation.addProperty(m.createProperty(RDFFileManager.ssnPrefix + "observedProperty"),
			m.createResource(ed.getPayloads().get(0).split("\\|")[2]));
	observation.addProperty(m.createProperty(RDFFileManager.ssnPrefix + "observedBy"), serviceID);
	// fake fixed foi
	observation
			.addProperty(
					m.createProperty(RDFFileManager.ssnPrefix + "featureOfInterest"),
					m.createResource("http://iot.ee.surrey.ac.uk/citypulse/datasets/aarhusculturalevents/culturalEvents_aarhus#context_do63jk2t8c3bjkfb119ojgkhs7"));

	observation.addProperty(m.createProperty(RDFFileManager.saoPrefix + "hasValue"), coordinates);
	// System.out.println("transformed: " + m.listStatements().toList().size());s
	return m.listStatements().toList();
}
 
Example 11
Source File: DataWrapper.java    From Benchmark with GNU General Public License v3.0 5 votes vote down vote up
public static List<Statement> getAarhusTrafficStatements(AarhusTrafficObservation data, EventDeclaration ed) {
	Model m = ModelFactory.createDefaultModel();
	if (ed != null)
		for (String pStr : ed.getPayloads()) {
			// if (s.contains("EstimatedTime")) {
			// Resource observedProperty = m.createResource(s);
			String obId = data.getObId();
			Resource observation = m.createResource(RDFFileManager.defaultPrefix + obId + UUID.randomUUID());
			CityBench.obMap.put(observation.toString(), data);
			// data.setObId(observation.toString());
			// System.out.println("OB: " + observation.toString());
			observation.addProperty(RDF.type, m.createResource(RDFFileManager.ssnPrefix + "Observation"));

			Resource serviceID = m.createResource(ed.getServiceId());
			observation.addProperty(m.createProperty(RDFFileManager.ssnPrefix + "observedBy"), serviceID);
			observation.addProperty(m.createProperty(RDFFileManager.ssnPrefix + "observedProperty"),
					m.createResource(pStr.split("\\|")[2]));
			Property hasValue = m.createProperty(RDFFileManager.saoPrefix + "hasValue");
			// System.out.println("Annotating: " + observedProperty.toString());
			if (pStr.contains("AvgSpeed"))
				observation.addLiteral(hasValue, data.getAverageSpeed());
			else if (pStr.contains("VehicleCount")) {
				double value = data.getVehicle_count();
				observation.addLiteral(hasValue, value);
			} else if (pStr.contains("MeasuredTime"))
				observation.addLiteral(hasValue, data.getAvgMeasuredTime());
			else if (pStr.contains("EstimatedTime"))
				observation.addLiteral(hasValue, data.getEstimatedTime());
			else if (pStr.contains("CongestionLevel"))
				observation.addLiteral(hasValue, data.getCongestionLevel());
			// break;
			// }
		}
	return m.listStatements().toList();
	// return null;

}
 
Example 12
Source File: CSPARQLLocationStream.java    From Benchmark with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected List<Statement> getStatements(SensorObservation so) throws NumberFormatException, IOException {
	String userStr = so.getFoi();
	String coordinatesStr = so.getValue().toString();
	Model m = ModelFactory.createDefaultModel();
	double lat = Double.parseDouble(coordinatesStr.split(",")[0]);
	double lon = Double.parseDouble(coordinatesStr.split(",")[1]);
	Resource serviceID = m.createResource(ed.getServiceId());
	//
	// Resource user = m.createResource(userStr);

	Resource observation = m.createResource(RDFFileManager.defaultPrefix + so.getObId() + UUID.randomUUID());
	CityBench.obMap.put(observation.toString(), so);
	observation.addProperty(RDF.type, m.createResource(RDFFileManager.ssnPrefix + "Observation"));
	// observation.addProperty(RDF.type, m.createResource(RDFFileManager.saoPrefix + "StreamData"));

	// location.addProperty(RDF.type, m.createResource(RDFFileManager.ctPrefix + "Location"));

	Resource coordinates = m.createResource();
	coordinates.addLiteral(m.createProperty(RDFFileManager.ctPrefix + "hasLatitude"), lat);
	coordinates.addLiteral(m.createProperty(RDFFileManager.ctPrefix + "hasLongitude"), lon);

	// observation.addProperty(m.createProperty(RDFFileManager.ssnPrefix + "featureOfInterest"), user);
	observation.addProperty(m.createProperty(RDFFileManager.ssnPrefix + "observedProperty"),
			m.createResource(ed.getPayloads().get(0).split("\\|")[2]));
	observation.addProperty(m.createProperty(RDFFileManager.ssnPrefix + "observedBy"), serviceID);
	// fake fixed foi
	observation
			.addProperty(
					m.createProperty(RDFFileManager.ssnPrefix + "featureOfInterest"),
					m.createResource("http://iot.ee.surrey.ac.uk/citypulse/datasets/aarhusculturalevents/culturalEvents_aarhus#context_do63jk2t8c3bjkfb119ojgkhs7"));

	observation.addProperty(m.createProperty(RDFFileManager.saoPrefix + "hasValue"), coordinates);
	// System.out.println("transformed: " + m.listStatements().toList().size());s
	return m.listStatements().toList();
}
 
Example 13
Source File: Course_Test.java    From neo4jena with Apache License 2.0 5 votes vote down vote up
public static void write(BatchInserter inserter) {
	InputStream in = FileManager.get().open( inputFileName );
	if (in == null) {
           throw new IllegalArgumentException( "File: " + inputFileName + " not found");
       }
       
	Model model = ModelFactory.createDefaultModel();

	StopWatch watch = new StopWatch();
       BatchHandler handler = new BatchHandler(inserter,500000,60);
       model.register(handler);
       
       model.read(in,"","TTL");	

       double triples = model.size();
       //log.info("Model loaded with " +  triples + " triples");
       System.out.println("Model loaded with " +  triples + " triples" + " time taken: " + watch.stop());
       //Map<String, String> prefixMap = model.getNsPrefixMap();
      // System.out.println("Prefix Mapping: " + prefixMap);
       
	//NeoGraph graph = new NeoGraph(njgraph);
	//graph.getPrefixMapping().setNsPrefixes(prefixMap);
	//graph.startBulkLoad();
	//log.info("Connection created");
	//Model njmodel = ModelFactory.createModelForGraph(graph);
	/*log.info("NeoGraph Model initiated");
	System.out.println("NeoGraph Model initiated");
	
	StopWatch watch = new StopWatch();
	//njmodel.add(model);
	
	long endTime = watch.stop();
	
	log.info("Total triples loaded are:"+ graph.size());
	System.out.println("Total triples loaded are:"+ graph.size());
	graph.stopBulkLoad();
	
	log.info("Storing completed (ms): " + endTime);
	System.out.println("Storing completed (ms): " + endTime);*/
}
 
Example 14
Source File: ClassMapServlet.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
private Model classMapListModel() {
	D2RServer server = D2RServer.fromServletContext(getServletContext());
	Model result = ModelFactory.createDefaultModel();
	Resource list = result.createResource(server.baseURI() + "all");
	list.addProperty(RDFS.label, "D2R Server contents");
	for (String name: server.getMapping().getResourceCollectionNames()) {
		Resource instances = result.createResource(server.baseURI() + "all/" + name);
		list.addProperty(RDFS.seeAlso, instances);
		instances.addProperty(RDFS.label, "List of all instances: " + name);
	}
	server.addDocumentMetadata(result, list);
	return result;
}
 
Example 15
Source File: MetadataCreator.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
public static Model loadMetadataTemplate(InputStream is) {
	try {
		Model tplModel = ModelFactory.createDefaultModel();
		tplModel.read(is, "about:prefix:", "TTL");
		return tplModel;
	} catch (JenaException e) {
		// ignore
	}
	return null;
}
 
Example 16
Source File: DecompositionRDFWriter.java    From TableDisentangler with GNU General Public License v3.0 5 votes vote down vote up
public DecompositionRDFWriter()
{
	model = ModelFactory.createDefaultModel();
	ArticleName = model.createProperty( ArticleDefault + "ArticleName" );
	ArticleID = model.createProperty( ArticleDefault + "ArticleID" );
	hasAuthor = model.createProperty( ArticleDefault + "hasAuthor" );
	Publisher =  model.createProperty( ArticleDefault + "Publisher" );
	Abstract = model.createProperty( ArticleDefault + "Abstract" );
	Venue = model.createProperty( ArticleDefault + "Venue" );
	ShortAbstract = model.createProperty( ArticleDefault + "ShortAbstract" );
	hasAffiliation = model.createProperty( ArticleDefault + "hasAffiliation" );
	Keywords = model.createProperty( ArticleDefault + "KeyWord" );
	TableOrder = model.createProperty( ArticleDefault + "TableOrder" );
	TableCaption = model.createProperty( ArticleDefault + "TableCaption" );
	TableFooter = model.createProperty( ArticleDefault + "TableFooter" );
	Table = model.createProperty( ArticleDefault + "HasTable" );
	TableType = model.createProperty( ArticleDefault + "TableType" );
	TablePragmaticType = model.createProperty( ArticleDefault + "TablePragmaticType" );
	TableXML= model.createProperty( ArticleDefault + "TableXML" );
	Cell = model.createProperty( ArticleDefault + "HasCell" );
	CellStub = model.createProperty( ArticleDefault + "CellStub" );
	CellStubValue = model.createProperty( ArticleDefault + "CellStubValue" );
	CellSubheadeing = model.createProperty( ArticleDefault + "CellSubheadeing" );
	CellHeader = model.createProperty( ArticleDefault + "CellHeader" );
	CellValue = model.createProperty( ArticleDefault + "CellValue" );
	CellType = model.createProperty( ArticleDefault + "CellType" );
	CellRow = model.createProperty( ArticleDefault + "CellRow" );
	HasNavigationalPath = model.createProperty( ArticleDefault + "HasNavigationalPath" );
	CellColumn = model.createProperty( ArticleDefault + "CellColumn" );
	Head00 = model.createProperty( ArticleDefault + "Head00" );
	NavigationalPath = model.createProperty( ArticleDefault + "NavigationalPath" );
	Root = model.createResource(ArticleDefault+"Root");
	HasArticle = model.createProperty( ArticleDefault + "HasArticle" );
}
 
Example 17
Source File: Course.java    From neo4jena with Apache License 2.0 5 votes vote down vote up
public static void write(GraphDatabaseService njgraph) {
	InputStream in = FileManager.get().open( inputFileName );
	if (in == null) {
           throw new IllegalArgumentException( "File: " + inputFileName + " not found");
       }
       
	Model model = ModelFactory.createDefaultModel();
       model.read(in,"","TTL");
       double triples = model.size();
       log.info("Model loaded with " +  triples + " triples");
       System.out.println("Model loaded with " +  triples + " triples");
       Map<String, String> prefixMap = model.getNsPrefixMap();
      // System.out.println("Prefix Mapping: " + prefixMap);
       
	NeoGraph graph = new NeoGraph(njgraph);
	graph.getPrefixMapping().setNsPrefixes(prefixMap);
	graph.startBulkLoad();
	log.info("Connection created");
	Model njmodel = ModelFactory.createModelForGraph(graph);
	log.info("NeoGraph Model initiated");
	System.out.println("NeoGraph Model initiated");
	
	//log.info(njmodel.add(model));
	//njmodel.add(model);
	StmtIterator iterator = model.listStatements();
	StopWatch watch = new StopWatch();
	int count = 0;
	while(iterator.hasNext()){
		njmodel.add(iterator.next());
		count++;
	}
	System.out.println("Total triples loaded are:"+ count);
	graph.stopBulkLoad();
	//log.info("Storing completed (ms): " + watch.stop());
	System.out.println("Storing completed (ms): " + watch.stop());
}
 
Example 18
Source File: DataTypeTesting.java    From semweb4j with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Test
public void testDataTypesWithUnknownType() throws Exception {
	
	// siehe dazu com.hp.hpl.jena.graph.test.TestTypedLiterals.java,
	// Funktion testUnknown()
	// das ganze funktioniert sowohl mit Jena2.2 als auch mit dem jena aus
	// dem cvs
	
	// das ganze Problem scheint wohl zu sein das Jena ziemlich abgefahrene
	// Sachen machen kann
	// mit daten typen und der valdierung und solchen advanced topics.
	// die Erwaeaehnte Test Datei zeigt das ziemlich eindrucksvoll.
	
	// Dieser gesamte Test testet direkt die Funktion von Jena, nicht von
	// rdf2go. (SG)
	
	// die erste DatenTyp URI
	String strTestA = new String("test://somedata-A");
	// die zweite DatenTyp URI
	String strTestB = new String("test://somedata-B");
	
	com.hp.hpl.jena.rdf.model.Model model = ModelFactory.createDefaultModel();
	
	// das hier scheint alles zu sein was notwendig ist damit Jena die data
	// typed literals
	// semantisch so behandelt wie wir es wollen
	// Behold !!
	JenaParameters.enableSilentAcceptanceOfUnknownDatatypes = true;
	
	Literal litA1 = model.createTypedLiteral("teststring", strTestA);
	Literal litA2 = model.createTypedLiteral("teststring", strTestA);
	Literal litB = model.createTypedLiteral("teststring", strTestB);
	
	// dann wollen wir mal schauen was passiert:
	
	// reflexivit�t: A == A , passt
	assertTrue(litA1.equals(litA1));
	// gleicher Inhalt, in zwei versch. Objekten, passt auch
	assertTrue(litA1.equals(litA2));
	// und zur sicherheit: 2 versch Datentyp URIs: nein
	assertFalse(litA1.equals(litB));
	
	// und nochmal der negativ Test:
	assertTrue(litB.equals(litB));
	assertFalse(litB.equals(litA1));
	assertFalse(litB.equals(litA2));
	assertEquals("Extract Datatype URI", litA1.getDatatypeURI(), strTestA);
	assertEquals("Extract value", "teststring", litA1.getLexicalForm());
	
	// im jena cvs geht auch folgendes, damit kann man das Object des Daten
	// Typs besser manipulieren
	// assertEquals("Extract value", l1.getValue(), new
	// BaseDatatype.TypedValue("foo", typeURI));
	
}
 
Example 19
Source File: DataTypeTesting.java    From semweb4j with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Test
public void testOldDataTypesUsedAsIntended() throws Exception {
	
	// laut der jena-dev Mailingliste, sollte man Datentypen so erzeugen:
	// siehe http://groups.yahoo.com/group/jena-dev/message/14052
	
	// String dtURI = tmpProp.getRange().getURI();
	// RDFDatatype dt = TypeMapper.getInstance().getTypeByName(dtURI);
	// Literal tmpLit = tmpModel.createTypedLiteral("123", dt );
	
	// leider f�hrt das dann dazu das "test"^^xsd:funky equal zu "test" ist,
	// da dann xsd:funky ein unknown data type ist und
	// somit "test"^^xsd:funky genau wie ein plain literal behandelt wird.
	
	// die erste DatenTyp URI
	// URI testA = URIUtils.createURI("test://somedata-A");
	String strTestA = new String("test://somedata-A");
	// die zweite DatenTyp URI
	// URI testB = URIUtils.createURI("test://somedata-B");
	String strTestB = new String("test://somedata-B");
	
	// der erste BaseDatatype wird von der ersten DatenTyp URI erzeugt
	RDFDatatype DTtestA1 = TypeMapper.getInstance().getTypeByName(strTestA);
	// der zweite BaseDatatype ebenso
	RDFDatatype DTtestA2 = TypeMapper.getInstance().getTypeByName(strTestA);
	// f�r den dritten BaseDatatype nehmen wir eine neue Datentyp URI
	RDFDatatype DTtestB = TypeMapper.getInstance().getTypeByName(strTestB);
	
	com.hp.hpl.jena.rdf.model.Model model = ModelFactory.createDefaultModel();
	
	Literal litA11 = model.createTypedLiteral("teststring", DTtestA1);
	Literal litA12 = model.createTypedLiteral("teststring", DTtestA1);
	Literal litA2 = model.createTypedLiteral("teststring", DTtestA2);
	@SuppressWarnings("unused")
	Literal litB = model.createTypedLiteral("teststring", DTtestB);
	
	// alle Literals haben den gleichen Wert !
	
	// dann wollen wir mal schauen was passiert:
	
	// reflexivit�t: A == A , passt
	assertTrue(litA11.equals(litA11));
	// gleicher Inhalt, in zwei versch. Objekten, passt auch
	assertTrue(litA11.equals(litA12));
	// zwei Objekte, mit untersch. BaseDatatypes, von der gleichen Datatype
	// URI:
	
	assertTrue(litA11.equals(litA2));
	// und zur sicherheit: 2 versch Datentyp URIs:
	
	// -> das sollte eigentlich nicht sein
	// TODO jena bug assertFalse(litA11.equals(litB));
	
}
 
Example 20
Source File: IOUtils.java    From semweb4j with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static Model read(Reader reader) {
	com.hp.hpl.jena.rdf.model.Model m = ModelFactory.createDefaultModel();
	readIntoJenaModel(m, reader);
	return new ModelImplJena(null, m);
}