Java Code Examples for com.hp.hpl.jena.rdf.model.Resource#addProperty()

The following examples show how to use com.hp.hpl.jena.rdf.model.Resource#addProperty() . 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: ClassMapServlet.java    From GeoTriples with Apache License 2.0 6 votes vote down vote up
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	D2RServer server = D2RServer.fromServletContext(getServletContext());
	server.checkMappingFileChanged();
	if (request.getPathInfo() == null) {
		new ModelResponse(classMapListModel(), request, response).serve();
		return;
	}
	String classMapName = request.getPathInfo().substring(1);
	Model resourceList = server.getMapping().getResourceCollection(classMapName).getInventoryModel();
	if (resourceList == null) {
		response.sendError(404, "Sorry, class map '" + classMapName + "' not found.");
		return;
	}
   	Resource classMap = resourceList.getResource(server.baseURI() + "all/" + classMapName);
   	Resource directory = resourceList.createResource(server.baseURI() + "all");
   	classMap.addProperty(RDFS.seeAlso, directory);
   	classMap.addProperty(RDFS.label, "List of all instances: " + classMapName);
   	directory.addProperty(RDFS.label, "D2R Server contents");
   	server.addDocumentMetadata(resourceList, classMap);
	new ModelResponse(resourceList, request, response).serve();
}
 
Example 2
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 3
Source File: RDFFileManager.java    From Benchmark with GNU General Public License v3.0 6 votes vote down vote up
private static void createSelections(Resource patternNode, Model m, EventPattern ep) {
	Property hasSelection = m.createProperty(cesPrefix + "hasSelection");
	Property hasNodeId = m.createProperty(cesPrefix + "hasNodeId");
	Property hasSelectedProperty = m.createProperty(cesPrefix + "selectedProperty");
	// System.out.p rintln("Creating selections:------------");
	for (Selection sel : ep.getSelections()) {
		// System.out.println("SEL: " + sel.toString());
		Resource pName = m.createResource(sel.getPropertyName());
		String nodeId = sel.getProvidedBy();
		// Resource pType = m.createResource(sel.getPropertyType());
		// EventDeclaration ed;
		// if (ep.isQuery() && sel.getOriginalED() != null)
		// ed = sel.getOriginalED();
		// Resource foi = m.createResource(sel.getFoi());
		patternNode.addProperty(
				hasSelection,
				m.createResource().addProperty(RDF.type, m.createResource(cesPrefix + "Selection"))
						.addProperty(hasNodeId, m.createLiteral(nodeId)).addProperty(hasSelectedProperty, pName));
		// if (ep.isQuery()) {// add property type and foi for query
		// pName.addProperty(RDF.type, pType).addProperty(m.createProperty(ssnPrefix + "isPropertyOf"), foi);
		// }
	}
}
 
Example 4
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 5
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 6
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 7
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 8
Source File: RdbToRdf.java    From TripleGeo with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 
 * Handle resource triples
 */
private void insertResourceTriplet(String s, String p, String o) {
  Resource resourceGeometry = model.createResource(s);
  Property property = model.createProperty(p);
  Resource resourceGeometry2 = model.createResource(o);
  resourceGeometry.addProperty(property, resourceGeometry2);
}
 
Example 9
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 10
Source File: ShpConnector.java    From TripleGeo with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 
 * Handle resource triples
 */
private void insertResourceTriplet(String s, String p, String o) {
  Resource resourceGeometry = model.createResource(s);
  Property property = model.createProperty(p);
  Resource resourceGeometry2 = model.createResource(o);
  resourceGeometry.addProperty(property, resourceGeometry2);
}
 
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: SemTime.java    From EventCoreference with Apache License 2.0 5 votes vote down vote up
public void addToJenaModelSimpleDocTimeInstant(Model model, SemObject semEvent) {

        this.getOwlTime().addToJenaModelOwlTimeInstant(model);

        Resource event = model.createResource(semEvent.getURI());
        Resource resource = model.createResource(this.getOwlTime().getDateStringURI());
        event.addProperty(Sem.hasTime, resource);

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

        //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);
*/

    }
 
Example 13
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 14
Source File: SemRelation.java    From EventCoreference with Apache License 2.0 5 votes vote down vote up
public void addToJenaDataSetSimpleWithoutName (HashMap<String, String> rename,  Model model) {

        if (rename.containsKey(this.getSubject())) { this.setSubject(rename.get(this.getSubject())); }
        if (rename.containsKey(this.getObject())) { this.setObject(rename.get(this.getObject())); }
        Resource subject = model.createResource(this.getSubject());
        Resource object = model.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 = model.createProperty(predicate);
                        subject.addProperty(srlProperty, object);
                    }
                }
            }
        }

    }
 
Example 15
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 16
Source File: RdbToRdf.java    From TripleGeo with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 
 * Insert a triple for the 'name' attribute of a feature
 */
private void insertResourceNameLiteral(String s, String p, String o, String lang) 
{
 	Resource resource = model.createResource(s);
   Property property = model.createProperty(p);
   if (lang != null) {
     Literal literal = model.createLiteral(o, lang);
     resource.addLiteral(property, literal);
   } else {
     resource.addProperty(property, o);
   }
 }
 
Example 17
Source File: SemTime.java    From EventCoreference with Apache License 2.0 5 votes vote down vote up
public void addToJenaModelTimeInterval(Model model) {
    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 interval = model.createResource(ResourcesUri.owltime + "Interval");
    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 18
Source File: RDFFileManager.java    From Benchmark with GNU General Public License v3.0 5 votes vote down vote up
private static void createEPModel(Resource profile, Model m, EventDeclaration ed) throws NodeRemovalException {
	if (ed.getEp() != null) {
		EventPattern ep = ed.getEp();
		String rootId = ep.getRootId();
		Resource bNode = m.createResource();
		if (profile == null)
			profile = m.createResource("DummyService-" + UUID.randomUUID() + "-Profile");
		profile.addProperty(m.createProperty(cesPrefix + "hasPattern"), bNode);
		createSelections(bNode, m, ep);
		traverseToCreate(rootId, bNode, ep, m);
	}

}
 
Example 19
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 20
Source File: SemRelation.java    From EventCoreference with Apache License 2.0 4 votes vote down vote up
public void addToJenaDataSet (Dataset ds, Model provenanceModel) {

        Model relationModel = ds.getNamedModel(this.id);

        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;
        boolean PLACE = false;
        boolean ACTOR = false;
        for (int i = 0; i < predicates.size(); i++) {
            String predicate = predicates.get(i);
            if (predicate.equalsIgnoreCase("hasFactBankValue")) {
                Property factProperty = relationModel.createProperty(ResourcesUri.nwrvalue + predicate);
                subject.addProperty(factProperty, this.getObject()); /// creates the literal as value
            }else {
                semProperty = getSemRelationProperty(predicate);
                if (isTemporalSemRelationProperty(predicate)) {
                        subject.addProperty(semProperty, object);
                        subject.addProperty(Sem.hasTime, object); /// additional hasTime relation to generalize
                }
                else {
                    if (!semProperty.getLocalName().equals(Sem.hasActor.getLocalName()) &&
                        !semProperty.getLocalName().equals(Sem.hasPlace.getLocalName())) {
                        predicate = getRoleRelation(predicate);
                        if (!predicate.isEmpty()) {
                            Property srlProperty = relationModel.createProperty(predicate);
                            subject.addProperty(srlProperty, object);

                            String predicateValue = predicate;
                            int idx = predicateValue.lastIndexOf("/");
                            if (idx > -1) predicateValue = predicateValue.substring(idx + 1);
                            if (RoleLabels.isLOCATION(predicateValue)) {
                                PLACE = true;
                            } else {
                                ACTOR = true;
                            }
                        }
                    }
                }

            }
        }
        //// if at the end of the loop we detected a location role
        if (PLACE) {
                subject.addProperty(Sem.hasPlace, object);
        }
        //// if at the end of the loop we detect an actor role
        if (ACTOR) {
            subject.addProperty(Sem.hasActor, object);
        }

        Resource provenanceResource = provenanceModel.createResource(this.id);

        for (int i = 0; i < nafMentions.size(); i++) {
            NafMention nafMention = nafMentions.get(i);
            Property property = provenanceModel.createProperty(ResourcesUri.gaf+"denotedBy");
            Resource targetResource = provenanceModel.createResource(nafMention.toString());
            provenanceResource.addProperty(property, targetResource);

        }
    }