Java Code Examples for com.hp.hpl.jena.rdf.model.Model#createResource()

The following examples show how to use com.hp.hpl.jena.rdf.model.Model#createResource() . 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: CQELSAarhusWeatherStream.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 2
Source File: Mapping.java    From xcurator with Apache License 2.0 6 votes vote down vote up
public static Set<String> getAllTypes(Model model, String typePrefix) {
    Resource rootResource = model.createResource(typePrefix);

    com.hp.hpl.jena.rdf.model.Property classProperty = model.createProperty("http://dblab.cs.toronto.edu/project/xcurator/0.1#classes");
    Bag classBag = model.createBag("http://dblab.cs.toronto.edu/project/xcurator/0.1#classBag");
    model.add(rootResource, classProperty, classBag);

    Set<String> ret = new HashSet<String>();

    NodeIterator iterator = classBag.iterator();
    while (iterator.hasNext()) {
        Resource resource = (Resource) iterator.next();
        ret.add(resource.getURI());
    }

    return ret;
}
 
Example 3
Source File: SemTime.java    From EventCoreference with Apache License 2.0 6 votes vote down vote up
public void addToJenaModelDocTimeInterval(Model model) {
    if (this.getPhraseCounts().size() > 0) {
        OwlTime owlTime = new OwlTime();
        owlTime.parsePublicationDate(getPhrase());
        owlTime.addToJenaModelOwlTimeInstant(model);

        Resource resource = model.createResource(this.getURI());
        for (int i = 0; i < this.getPhraseCounts().size(); i++) {
            PhraseCount phraseCount = this.getPhraseCounts().get(i);
            if (!phraseCount.getPhrase().isEmpty()) {
                resource.addProperty(RDFS.label, model.createLiteral(phraseCount.getPhrase()));
            }
        }

        resource.addProperty(RDF.type, Sem.Time);
        Resource interval = model.createResource(ResourcesUri.owltime + "Interval");
        resource.addProperty(RDF.type, interval);

        Resource value = model.createResource(owlTime.getDateStringURI());
        Property property = model.createProperty(ResourcesUri.owltime + "inDateTime");
        resource.addProperty(property, value);
    }
}
 
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: CSPARQLAarhusParkingStream.java    From Benchmark with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected List<Statement> getStatements(SensorObservation so) throws NumberFormatException, IOException {
	Model m = ModelFactory.createDefaultModel();
	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"));
	Resource serviceID = m.createResource(ed.getServiceId());
	observation.addProperty(m.createProperty(RDFFileManager.ssnPrefix + "observedBy"), serviceID);
	// Resource property = m.createResource(s.split("\\|")[2]);
	// property.addProperty(RDF.type, m.createResource(s.split("\\|")[0]));
	observation.addProperty(m.createProperty(RDFFileManager.ssnPrefix + "observedProperty"),
			m.createResource(ed.getPayloads().get(0).split("\\|")[2]));
	Property hasValue = m.createProperty(RDFFileManager.saoPrefix + "hasValue");
	// Literal l;
	// System.out.println("Annotating: " + observedProperty.toString());
	// if (observedProperty.contains("AvgSpeed"))
	observation.addLiteral(hasValue, ((AarhusParkingObservation) so).getVacancies());
	// observation.addLiteral(m.createProperty(RDFFileManager.ssnPrefix + "featureOfInterest"),
	// ((AarhusParkingObservation) so).getGarageCode());
	return m.listStatements().toList();
}
 
Example 6
Source File: DataWrapper.java    From Benchmark with GNU General Public License v3.0 6 votes vote down vote up
public static List<Statement> getAarhusParkingStatements(SensorObservation so, EventDeclaration ed) {
	Model m = ModelFactory.createDefaultModel();
	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"));
	Resource serviceID = m.createResource(ed.getServiceId());
	observation.addProperty(m.createProperty(RDFFileManager.ssnPrefix + "observedBy"), serviceID);
	// Resource property = m.createResource(s.split("\\|")[2]);
	// property.addProperty(RDF.type, m.createResource(s.split("\\|")[0]));
	observation.addProperty(m.createProperty(RDFFileManager.ssnPrefix + "observedProperty"),
			m.createResource(ed.getPayloads().get(0).split("\\|")[2]));
	Property hasValue = m.createProperty(RDFFileManager.saoPrefix + "hasValue");
	// Literal l;
	// System.out.println("Annotating: " + observedProperty.toString());
	// if (observedProperty.contains("AvgSpeed"))
	observation.addLiteral(hasValue, ((AarhusParkingObservation) so).getVacancies());
	// observation.addLiteral(m.createProperty(RDFFileManager.ssnPrefix + "featureOfInterest"),
	// ((AarhusParkingObservation) so).getGarageCode());
	return m.listStatements().toList();
}
 
Example 7
Source File: DataWrapper.java    From Benchmark with GNU General Public License v3.0 6 votes vote down vote up
public static List<Statement> getAarhusPollutionStatement(SensorObservation so, EventDeclaration ed) {
	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 8
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 9
Source File: SemRelation.java    From EventCoreference with Apache License 2.0 5 votes vote down vote up
public void addToJenaDataSetSimple (HashMap<String, String> rename, Dataset ds) {

        Model relationModel = ds.getNamedModel(this.id);
        if (rename.containsKey(this.getSubject())) { this.setSubject(rename.get(this.getSubject())); }
        if (rename.containsKey(this.getObject())) { this.setObject(rename.get(this.getObject())); }
        Resource subject = relationModel.createResource(this.getSubject());
        Resource object = relationModel.createResource(this.getObject());


        /// since we no longer distinguish places from actors, we now check the predicates for propbank AM-LOC
        /// if so we use sem:hasPlace otherwise we take the semType value from the hasSem predicate
        Property semProperty = null;
        for (int i = 0; i < predicates.size(); i++) {
            String predicate = predicates.get(i);
            semProperty = getSemRelationProperty(predicate);
            if (isTemporalSemRelationProperty(predicate)) {
                    subject.addProperty(semProperty, object);
            }
            else {
                if (!semProperty.getLocalName().equals(Sem.hasActor.getLocalName()) &&
                    !semProperty.getLocalName().equals(Sem.hasPlace.getLocalName())) {
                    predicate = getSimpleRoleRelation(predicate);
                    //System.err.println("predicate:"+predicate);
                    //predicate = getFramenetRoleRelation(predicates.get(i));
                    if (!predicate.isEmpty()) {
                        Property srlProperty = relationModel.createProperty(predicate);
                        subject.addProperty(srlProperty, object);
                    }
                }
            }
        }

    }
 
Example 10
Source File: SPARQLEndPoint.java    From LodView with MIT License 5 votes vote down vote up
public Model extractData(Model result, String IRI, String sparql, List<String> queries) throws Exception {

		// System.out.println("executing query on " + sparql);
		Resource subject = result.createResource(IRI);
		for (String query : queries) {
			QueryExecution qe = QueryExecutionFactory.sparqlService(sparql, parseQuery(query, IRI, null, -1, null));
			try {
				ResultSet rs = qe.execSelect();

				List<Statement> sl = new ArrayList<Statement>();
				while (rs.hasNext()) {
					QuerySolution qs = rs.next();
					RDFNode subject2 = qs.get("s");
					RDFNode property = qs.get("p");
					RDFNode object = qs.get("o");
					result.add(result.createStatement(subject2 != null ? subject2.asResource() : subject, property.as(Property.class), object));
				}
				result.add(sl);
			} catch (Exception e) {
				e.printStackTrace();
				throw new Exception("error in query execution: " + e.getMessage());
			} finally {
				qe.close();
			}
		}
		return result;
	}
 
Example 11
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 12
Source File: CQELSLocationStream.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: 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 14
Source File: RDFFileManager.java    From Benchmark with GNU General Public License v3.0 5 votes vote down vote up
private static void createFilter(Resource bnode, Filter f, String cid, Model m) {
	Property hasFilter = m.createProperty(cesPrefix + "hasFilter");

	Resource filter = m.createResource();

	filter.addProperty(RDF.type, m.createResource(cesPrefix + "Filter"));
	filter.addProperty(m.createProperty(cesPrefix + "onPayload"), m.createResource(f.getVar()));
	if (cid != null) {
		// bnode = m.createResource();
		filter.addProperty(m.createProperty(cesPrefix + "onEvent"), m.createResource(cid));
	}
	bnode.addProperty(hasFilter, filter);
	Property op;
	if (f.getOp() == Filter.eq)
		op = m.createProperty(emvoPrefix + "equals");
	else if (f.getOp() == Filter.lt)
		op = m.createProperty(emvoPrefix + "lessThan");
	else if (f.getOp() == Filter.leq)
		op = m.createProperty(emvoPrefix + "lessOrEqualThan");
	else if (f.getOp() == Filter.gt)
		op = m.createProperty(emvoPrefix + "greaterThan");
	else {
		op = m.createProperty(emvoPrefix + "greaterOrEqualThan");
	}
	// Literal val = m.(f.getVal());
	if (f.getVal() instanceof String)
		filter.addLiteral(op, m.createTypedLiteral((String) f.getVal()));
	else if (f.getVal() instanceof Integer)
		filter.addLiteral(op, m.createTypedLiteral((Integer) f.getVal()));
	else
		filter.addLiteral(op, m.createTypedLiteral(Double.parseDouble(f.getVal().toString())));
}
 
Example 15
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 16
Source File: SemTime.java    From EventCoreference with Apache License 2.0 5 votes vote down vote up
public void addToJenaModelTimeInstant(Model model, OwlTime owlTime) {
    this.getOwlTime().addToJenaModelOwlTimeInstant(model);

    Resource resource = model.createResource(this.getURI());
    for (int i = 0; i < this.getPhraseCounts().size(); i++) {
        PhraseCount phraseCount = this.getPhraseCounts().get(i);
        if (!phraseCount.getPhrase().isEmpty()) {
            resource.addProperty(RDFS.label, model.createLiteral(phraseCount.getPhrase()));
        }
    }

    resource.addProperty(RDF.type, Sem.Time);

    Resource aResource = model.createResource(ResourcesUri.owltime + "Instant");
    resource.addProperty(RDF.type, aResource);

    Resource value = model.createResource(owlTime.getDateStringURI());
    Property property = model.createProperty(ResourcesUri.owltime + "inDateTime");
    resource.addProperty(property, value);

    for (int i = 0; i < this.getNafMentions().size(); i++) {
        NafMention nafMention = this.getNafMentions().get(i);
        Property gaf = model.createProperty(ResourcesUri.gaf + "denotedBy");
        Resource targetResource = model.createResource(nafMention.toString());
        resource.addProperty(gaf, targetResource);
    }
}
 
Example 17
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 18
Source File: AssemblerExample.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	// Load assembler specification from file
	Model assemblerSpec = FileManager.get().loadModel("doc/example/assembler.ttl");
	
	// Get the model resource
	Resource modelSpec = assemblerSpec.createResource(assemblerSpec.expandPrefix(":myModel"));
	
	// Assemble a model
	Model m = Assembler.general.openModel(modelSpec);
	
	// Write it to System.out
	m.write(System.out);

	m.close();
}
 
Example 19
Source File: SemTime.java    From EventCoreference with Apache License 2.0 5 votes vote down vote up
public void addToJenaModelDocTimeInstant(Model model) {

        this.getOwlTime().addToJenaModelOwlTimeInstant(model);

        Resource resource = model.createResource(this.getURI());
        if (!this.getTopPhraseAsLabel().isEmpty()) {
            resource.addProperty(RDFS.label, model.createLiteral(this.getTopPhraseAsLabel()));
        }

        /*for (int i = 0; i < phraseCounts.size(); i++) {
            PhraseCount phraseCount = phraseCounts.get(i);
            resource.addProperty(RDFS.label, model.createLiteral(phraseCount.getPhrase()));
        }*/

        //resource.addProperty(RDF.type, Sem.Time);
        // System.out.println("this.getOwlTime().toString() = " + this.getOwlTime().toString());
        Resource interval = model.createResource(ResourcesUri.owltime + "Instant");
        resource.addProperty(RDF.type, interval);

        Resource value = model.createResource(this.getOwlTime().getDateStringURI());
        Property property = model.createProperty(ResourcesUri.owltime + "inDateTime");
        resource.addProperty(property, value);

        for (int i = 0; i < this.getNafMentions().size(); i++) {
            NafMention nafMention = this.getNafMentions().get(i);
            Property gaf = model.createProperty(ResourcesUri.gaf + "denotedBy");
            Resource targetResource = model.createResource(nafMention.toString());
            resource.addProperty(gaf, targetResource);

        }
    }
 
Example 20
Source File: SparqlQueryBase.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
public RDFNode convertTypeLiteral(Model model, InternalParam param)
		throws DataServiceFault {
	String value = param.getValue().getScalarValue();
	String type = param.getSqlType();
	if (type == null) {
		return model.createTypedLiteral(value);
	} else if (DBConstants.XSDTypes.INTEGER.equals(type) ) {
		return model.createTypedLiteral(value,XSDDatatype.XSDinteger);
	} else if (DBConstants.XSDTypes.ANYURI.equals(type)) {
		return model.createResource(value);
	} else if (DBConstants.XSDTypes.DECIMAL.equals(type)) {
		return model.createTypedLiteral(value,XSDDatatype.XSDdecimal);
	} else if (DBConstants.XSDTypes.DOUBLE.equals(type)) {
		return model.createTypedLiteral(value,XSDDatatype.XSDdouble);
	} else if (DBConstants.XSDTypes.FLOAT.equals(type)) {
		return model.createTypedLiteral(value,XSDDatatype.XSDfloat);
	} else if (DBConstants.XSDTypes.STRING.equals(type)) {
		return model.createTypedLiteral(value);
	} else if (DBConstants.XSDTypes.BOOLEAN.equals(type)) {
		return model.createTypedLiteral(value,XSDDatatype.XSDboolean);
	} else if (DBConstants.XSDTypes.LONG.equals(type)) {
		return model.createTypedLiteral(value,XSDDatatype.XSDlong);
	} else if (DBConstants.XSDTypes.DATE.equals(type) ) {
		return model.createTypedLiteral(value,XSDDatatype.XSDdate);
	} else if (DBConstants.XSDTypes.DATETIME.equals(type) ) {
		return model.createTypedLiteral(value,XSDDatatype.XSDdateTime);
	} else if (DBConstants.XSDTypes.TIME.equals(type)) {
		return model.createTypedLiteral(value,XSDDatatype.XSDtime);
	} else if (DBConstants.XSDTypes.GYEARMONTH.equals(type) ) {
		return model.createTypedLiteral(value,XSDDatatype.XSDgYearMonth);
	} else if (DBConstants.XSDTypes.GYEAR.equals(type) ) {
		return model.createTypedLiteral(value,XSDDatatype.XSDgYear);
	} else if (DBConstants.XSDTypes.GMONTHDAY.equals(type)) {
		return model.createTypedLiteral(value,XSDDatatype.XSDgMonthDay);
	} else if (DBConstants.XSDTypes.GDAY.equals(type)) {
		return model.createTypedLiteral(value,XSDDatatype.XSDgDay);
	} else if (DBConstants.XSDTypes.GMONTH.equals(type)) {
		return model.createTypedLiteral(value,XSDDatatype.XSDgMonth);
	} else if (DBConstants.XSDTypes.HEXBINARY.equals(type)) {
		return model.createTypedLiteral(value,XSDDatatype.XSDhexBinary);
	} else if (DBConstants.XSDTypes.BASE64BINARY.equals(type)) {
		return model.createTypedLiteral(value,XSDDatatype.XSDbase64Binary);
	} else if (DBConstants.XSDTypes.QNAME.equals(type)) {
		return model.createTypedLiteral(value,XSDDatatype.XSDQName);
	} else if (DBConstants.XSDTypes.NOTATION.equals(type)) {
		return model.createTypedLiteral(value,XSDDatatype.XSDNOTATION);
	} else {
		throw new DataServiceFault("[" + this.getDataService().getName()
				+ "]  Found Unsupported data type : " + type
				+ " as input parameter.");
	}

}