com.hp.hpl.jena.rdf.model.Statement Java Examples

The following examples show how to use com.hp.hpl.jena.rdf.model.Statement. 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: JsonFromRdf.java    From EventCoreference with Apache License 2.0 6 votes vote down vote up
static boolean mentionInList (ArrayList<Statement> statements, Vector<String> perspectiveVector) throws JSONException {
    for (int i = 0; i < statements.size(); i++) {
        Statement statement = statements.get(i);

        String predicate = statement.getPredicate().getURI();
        if (predicate.endsWith("#denotedBy")) {
            String object = "";
            if (statement.getObject().isLiteral()) {
                object = statement.getObject().asLiteral().toString();
            } else if (statement.getObject().isURIResource()) {
                object = statement.getObject().asResource().getURI();
            }
            if (perspectiveVector.contains(object)) {
                return true;
            }
        }
    }
    return false;
}
 
Example #2
Source File: GeneralR2RMLCompiler.java    From GeoTriples with Apache License 2.0 6 votes vote down vote up
public List<RDFNode> getRDFNodes(Resource r, Property p, R2RMLReader.NodeType acceptableNodes) {
	List<RDFNode> result = new ArrayList<RDFNode>();
	StmtIterator it = r.listProperties(p);
	while (it.hasNext()) {
		Statement stmt = it.next();
		if (acceptableNodes.isTypeOf(stmt.getObject())) {
			result.add(stmt.getObject());
		} else {
			if (acceptableNodes.coerce(stmt.getObject()) != null) {
				result.add(acceptableNodes.coerce(stmt.getObject()));
			}
		}
	}
	Collections.sort(result, RDFComparator.getRDFNodeComparator());
	return result;
}
 
Example #3
Source File: SPARQLEndPoint.java    From LodView with MIT License 6 votes vote down vote up
public Model extractLocalData(Model result, String IRI, Model m, List<String> queries) throws Exception {

		// System.out.println("executing query on IRI");
		Resource subject = result.createResource(IRI);
		for (String query : queries) {
			QueryExecution qe = QueryExecutionFactory.create(parseQuery(query, IRI, null, -1, null), m);
			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 #4
Source File: GetEntityCounts.java    From EventCoreference with Apache License 2.0 6 votes vote down vote up
static void updateNWRCounts (Statement statement) {
    String subject = statement.getSubject().toString();
    //System.out.println("subject = " + subject);
    if (subject.contains("/entities/")) {
        if (TrigUtil.isGafTriple(statement)) {
            if (nwrEntityCounts.containsKey(subject)) {
                Integer cnt = nwrEntityCounts.get(subject);
                cnt++;
                nwrEntityCounts.put(subject, cnt);
            }
            else {
                nwrEntityCounts.put(subject,1);
            }
        }
    }
}
 
Example #5
Source File: TrigToJsonTimeLine.java    From EventCoreference with Apache License 2.0 6 votes vote down vote up
static JSONObject getLabelsJSONObjectFromInstanceStatement (ArrayList<Statement> statements) throws JSONException {
    JSONObject jsonClassesObject = new JSONObject();
    ArrayList<String> coveredValues = new ArrayList<String>();
    for (int i = 0; i < statements.size(); i++) {
        Statement statement = statements.get(i);

        String predicate = statement.getPredicate().getURI();
        if (predicate.endsWith("#label")) {
            String object = "";
            if (statement.getObject().isLiteral()) {
                object = statement.getObject().asLiteral().toString();
            } else if (statement.getObject().isURIResource()) {
                object = statement.getObject().asResource().getURI();
            }
            String [] values = object.split(",");
            for (int j = 0; j < values.length; j++) {
                String value = values[j];
                if (!coveredValues.contains(value)) {
                    coveredValues.add(value);
                    jsonClassesObject.append("labels", value);
                }
            }
        }
    }
    return jsonClassesObject;
}
 
Example #6
Source File: WP2N3JenaWriterPP.java    From GeoTriples with Apache License 2.0 6 votes vote down vote up
@Override
protected int countProperties(Resource r, Property p) 
{
	int numProp = 0 ;
	StmtIterator sIter = r.listProperties(p) ;
	for ( ; sIter.hasNext() ; )
	{
		Statement stmnt=sIter.nextStatement() ;
		if(! stmnt.getObject().toString().startsWith("null"))
		{
			numProp++ ;
		}
	}
	sIter.close() ;
	return numProp ;
}
 
Example #7
Source File: JsonFromRdf.java    From EventCoreference with Apache License 2.0 6 votes vote down vote up
static boolean prefLabelInList (ArrayList<Statement> statements, ArrayList<String> blacklist) throws JSONException {
    for (int i = 0; i < statements.size(); i++) {
        Statement statement = statements.get(i);

        String predicate = statement.getPredicate().getURI();
        //System.out.println("predicate = " + predicate);
       // http://www.w3.org/2004/02/skos/core#prefLabel
        if (predicate.toLowerCase().endsWith("#preflabel")) {
            String object = "";
            if (statement.getObject().isLiteral()) {
                object = statement.getObject().asLiteral().toString();
            } else if (statement.getObject().isURIResource()) {
                object = statement.getObject().asResource().getURI();
            }
            String [] values = object.split(",");
            for (int j = 0; j < values.length; j++) {
                String value = values[j];
                //System.out.println("value = " + value);
                if (blacklist.contains(value)) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example #8
Source File: ComplianceTests.java    From r2rml-parser with Apache License 2.0 6 votes vote down vote up
@Test
public void loadPersons() {
	if (connection == null)
		openConnection();

	for (int i = 94300; i < 500000; i++) {
		String q1 = "INSERT INTO eperson (eperson_id, email, password, salt, digest_algorithm, firstname, lastname, can_log_in, require_certificate, self_registered, last_active, sub_frequency, phone, netid, language) " +
				"VALUES (" + i +", 'nkons" + i + "@live.com', 'aa07c370f18e6306d481e29d04d28ea322f3ac5d746bd1122b4907518b37875b59283054d9e91fd049f39df2223ba3feb62f9cc2923e5614503d0b9b191d6606', '2d0155aa63818899d177ff988ddde7c5', 'SHA-512', '" + randomString() + "', '" + randomString() + "', 'true', 'false', 'false', NULL, NULL, NULL, NULL, 'en');";
		String q2 = "INSERT INTO epersongroup2eperson (id, eperson_group_id, eperson_id) VALUES (" + i + ", 1, " + i + ");";
	
		try {
			java.sql.Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
			int a = statement.executeUpdate(q1);
			int b = statement.executeUpdate(q2);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (i % 1000 == 0)
			log.info("At " + i);
	}
}
 
Example #9
Source File: SparqlExtractor.java    From wandora with GNU General Public License v3.0 6 votes vote down vote up
public void RDF2TopicMap(Model model, TopicMap map) {
    // list the statements in the Model
    StmtIterator iter = model.listStatements();
    Statement stmt = null;
    int counter = 0;

    while (iter.hasNext() && !forceStop()) {
        try {
            stmt = iter.nextStatement();  // get next statement
            handleStatement(stmt, map);
        }
        catch(Exception e) {
            log(e);
        }
        counter++;
        setProgress(counter);
        if(counter % 100 == 0) hlog("RDF statements processed: " + counter);

    }
    log("Total RDF statements processed: " + counter);
}
 
Example #10
Source File: TrigStats.java    From EventCoreference with Apache License 2.0 6 votes vote down vote up
static ArrayList<String> getSkosRelatedValuesFromInstanceStatement (ArrayList<Statement> statements) {
        ArrayList<String> result = new ArrayList<String>();
        for (int i = 0; i < statements.size(); i++) {
            Statement statement = statements.get(i);
            String predicate = statement.getPredicate().getURI();
            if (predicate.endsWith("#relatedMatch")) {
                String object = "";
                if (statement.getObject().isLiteral()) {
                    object = statement.getObject().asLiteral().toString();
                } else if (statement.getObject().isURIResource()) {
                    object = statement.getObject().asResource().getURI();
                }
                String[] values = object.split(",");
                for (int j = 0; j < values.length; j++) {
                    String value = values[j];
                    String property = JsonFromRdf.getNameSpaceString(value);
                    value = property + ":" + getValue(value);
                    if (!result.contains(value)) {
                        result.add(value);
                    }
                }
            }
        }
        return result;
}
 
Example #11
Source File: TrigUtil.java    From EventCoreference with Apache License 2.0 6 votes vote down vote up
static public boolean isEventInstance (Statement statement) {
    String predicate = statement.getPredicate().getURI();
    if (predicate.endsWith("#type")) {
        String object = "";
        if (statement.getObject().isLiteral()) {
            object = statement.getObject().asLiteral().toString();
        } else if (statement.getObject().isURIResource()) {
            object = statement.getObject().asResource().getURI();
        }
        String[] values = object.split(",");
        for (int j = 0; j < values.length; j++) {
            String value = values[j];
            String property = getNameSpaceString(value);
            //  System.out.println("value = " + value);
            //    System.out.println("property = " + property);
            if (value.endsWith("Event") && property.equalsIgnoreCase("sem")) {
                return true;
            }
        }
    }
    return false;
}
 
Example #12
Source File: R2RMLReader.java    From GeoTriples with Apache License 2.0 6 votes vote down vote up
public List<RDFNode> getRDFNodes(Resource r, Property p, NodeType acceptableNodes) {
	List<RDFNode> result = new ArrayList<RDFNode>();
	StmtIterator it = r.listProperties(p);
	while (it.hasNext()) {
		Statement stmt = it.next();
		remainingTriples.remove(stmt);
		if (acceptableNodes.isTypeOf(stmt.getObject())) {
			result.add(stmt.getObject());
		} else {
			if (acceptableNodes.coerce(stmt.getObject()) != null) {
				result.add(acceptableNodes.coerce(stmt.getObject()));
			}
			report.report(acceptableNodes.ifNot, r, p, stmt.getObject());
		}
	}
	Collections.sort(result, RDFComparator.getRDFNodeComparator());
	return result;
}
 
Example #13
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 #14
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 #15
Source File: TrigUtil.java    From EventCoreference with Apache License 2.0 6 votes vote down vote up
static public String getObjectValue (Statement statement) {
        String object = "";
        String value = "";
        if (statement.getObject().isLiteral()) {
            value = statement.getObject().asLiteral().toString();
        } else if (statement.getObject().isURIResource()) {
            value = statement.getObject().asResource().getLocalName();
        }
/*        int idx = value.lastIndexOf("/");
        if (idx>-1) {
            value = value.substring(value.lastIndexOf("/"));
        }*/
        value = getValue(statement.getObject().toString());
        String nameSpace =  getNameSpaceString(statement.getObject().toString());
        if (nameSpace.isEmpty()) {
            object = value;
        }
        else {
            object = nameSpace+":" + value;
        }
        //  System.out.println("object = " + object);
        return object;
    }
 
Example #16
Source File: JsonFromRdf.java    From EventCoreference with Apache License 2.0 6 votes vote down vote up
static JSONObject getLabelsJSONObjectFromInstanceStatement (ArrayList<Statement> statements) throws JSONException {
    JSONObject jsonClassesObject = new JSONObject();
    ArrayList<String> coveredValues = new ArrayList<String>();
    for (int i = 0; i < statements.size(); i++) {
        Statement statement = statements.get(i);

        String predicate = statement.getPredicate().getURI();
        if (predicate.endsWith("#label")) {
            String object = "";
            if (statement.getObject().isLiteral()) {
                object = statement.getObject().asLiteral().toString();
            } else if (statement.getObject().isURIResource()) {
                object = statement.getObject().asResource().getURI();
            }
            String [] values = object.split(",");
            for (int j = 0; j < values.length; j++) {
                String value = values[j];
                if (!coveredValues.contains(value)) {
                    coveredValues.add(value);
                    jsonClassesObject.append("labels", value);
                }
            }
        }
    }
    return jsonClassesObject;
}
 
Example #17
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 #18
Source File: JsonFromRdf.java    From EventCoreference with Apache License 2.0 6 votes vote down vote up
static JSONObject getMentionsJSONObjectFromInstanceStatement (ArrayList<Statement> statements) throws JSONException {
    JSONObject jsonClassesObject = new JSONObject();
    String predicate = "";
    for (int i = 0; i < statements.size(); i++) {
        Statement statement = statements.get(i);

        predicate = statement.getPredicate().getURI();
        if (predicate.endsWith("#denotedBy")) {
            String object = "";
            if (statement.getObject().isLiteral()) {
                object = statement.getObject().asLiteral().toString();
            } else if (statement.getObject().isURIResource()) {
                object = statement.getObject().asResource().getURI();
            }
            jsonClassesObject.append("mentions", getMentionObjectFromMentionURI(object));
        }
    }
    /*try {
        jsonClassesObject.get("mentions");
    } catch (JSONException e) {
        e.printStackTrace();
        System.out.println("No mentions for predicate = "+predicate);

    }*/
    return jsonClassesObject;
}
 
Example #19
Source File: CQELSAarhusParkingStream.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();
	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 #20
Source File: JenaUtils.java    From xcurator with Apache License 2.0 5 votes vote down vote up
public static List<Statement> getBestMatchingStatements(OntModel ontology, StringMetric metric, String term) {
    StmtIterator iter
            = ontology.listStatements(new SimpleSelector(null, RDFS.label, (RDFNode) null));

    double maxSimilarity = Double.MIN_VALUE;
    List<Statement> bestChoices = new LinkedList<Statement>();

    while (iter.hasNext()) {
        Statement st = iter.next();
        String objectStr = st.getObject().asLiteral().getString();

        double similarity = metric.getSimilarity(term, objectStr);

        if (similarity <= 0) {
            continue;
        }

        if (similarity > maxSimilarity) {
            maxSimilarity = similarity;
            bestChoices.clear();
        } else if (similarity == maxSimilarity) {
            bestChoices.add(st);
        }
    }

    return bestChoices;
}
 
Example #21
Source File: TrigToJsonTimeLine.java    From EventCoreference with Apache License 2.0 5 votes vote down vote up
static boolean hasFrameNet (ArrayList<Statement> triples) {
    for (int i = 0; i < triples.size(); i++) {
        Statement statement = triples.get(i);
        String object = "";
        if (statement.getObject().isLiteral()) {
            object = statement.getObject().asLiteral().toString();
        } else if (statement.getObject().isURIResource()) {
            object = statement.getObject().asResource().getURI();
        }
        if (object.indexOf("framenet")>-1) {
            return true;
        }
    }
    return false;
}
 
Example #22
Source File: SolRDF.java    From SolRDF with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a given set of statements to a named graph.
 * 
 * @param uri the graph URI.
 * @param statements the list of statements.
 * @throws UnableToAddException in case of add (local or remote) failure.
 */
public void add(final String uri, final Statement [] statements) throws UnableToAddException {
	try {
		remoteDataset.add(uri, model(uri).add(statements));
	} catch (final Exception exception) {
		throw new UnableToAddException(exception);
	}
}
 
Example #23
Source File: SolRDF.java    From SolRDF with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a given set of statements to the unnamed graph.
 * 
 * @param statements the list of statements.
 * @throws UnableToAddException in case of add (local or remote) failure.
 */
public void add(final Statement [] statements) throws UnableToAddException {
	try {
		remoteDataset.add(model().add(statements));
	} catch (final Exception exception) {
		throw new UnableToAddException(exception);
	}
}
 
Example #24
Source File: TrigUtil.java    From EventCoreference with Apache License 2.0 5 votes vote down vote up
static public boolean hasStatement (ArrayList<Statement> statements, Statement s) {
    for (int i = 0; i < statements.size(); i++) {
        Statement statement = statements.get(i);
        if (statement.getSubject().equals(s.getSubject()) &&
                statement.getPredicate().equals(s.getPredicate()) &&
                statement.getObject().equals(s.getObject())) {
            return true;
        }
    }

    return false;
}
 
Example #25
Source File: TrigStats.java    From EventCoreference with Apache License 2.0 5 votes vote down vote up
static int countMentions (ArrayList<Statement> statements) {
    int n = 0;
    for (int i = 0; i < statements.size(); i++) {
        Statement statement = statements.get(i);
        String predicate = statement.getPredicate().getURI();
        if (predicate.endsWith("#denotedBy")) {
            n++;
        }
    }
    return n;
}
 
Example #26
Source File: SolRDF.java    From SolRDF with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a given set of statements to the unnamed graph.
 * 
 * @param statements the list of statements.
 * @throws UnableToAddException in case of add (local or remote) failure.
 */
public void add(final List<Statement> statements) throws UnableToAddException {
	try {
		remoteDataset.add(model().add(statements));
	} catch (final Exception exception) {
		throw new UnableToAddException(exception);
	}
}
 
Example #27
Source File: TrigToJsonTimeLine.java    From EventCoreference with Apache License 2.0 5 votes vote down vote up
static JSONObject getClassesJSONObjectFromInstanceStatement (ArrayList<Statement> statements) throws JSONException {
    JSONObject jsonClassesObject = new JSONObject();
    ArrayList<String> coveredValues = new ArrayList<String>();

    for (int i = 0; i < statements.size(); i++) {
        Statement statement = statements.get(i);

        String predicate = statement.getPredicate().getURI();
        if (predicate.endsWith("#type")) {
            String object = "";
            if (statement.getObject().isLiteral()) {
                object = statement.getObject().asLiteral().toString();
            } else if (statement.getObject().isURIResource()) {
                object = statement.getObject().asResource().getURI();
            }
            String [] values = object.split(",");
            for (int j = 0; j < values.length; j++) {
                String value = values[j];
                String property = getNameSpaceString(value);
                if (!property.isEmpty() && !property.equalsIgnoreCase("sem")) {
                    value = getValue(value);
                    if (!coveredValues.contains(property+value)) {
                        coveredValues.add(property+value);
                        jsonClassesObject.append(property, value);
                    }
                }
            }
        }
    }
    return jsonClassesObject;
}
 
Example #28
Source File: GetEventStats.java    From EventCoreference with Apache License 2.0 5 votes vote down vote up
static boolean hasStatement (ArrayList<Statement> statements, Statement s) {
    for (int i = 0; i < statements.size(); i++) {
        Statement statement = statements.get(i);
        if (statement.getSubject().equals(s.getSubject()) &&
                statement.getPredicate().equals(s.getPredicate()) &&
                statement.getObject().equals(s.getObject())) {
            return true;
        }
    }

    return false;
}
 
Example #29
Source File: JsonFromRdf.java    From EventCoreference with Apache License 2.0 5 votes vote down vote up
static public String getTimeAnchor (HashMap<String, ArrayList<Statement>> tripleMapInstances,
                             ArrayList<Statement> triples) {
    for (int i = 0; i < triples.size(); i++) {
        Statement statement = triples.get(i);
        String predicate = statement.getPredicate().getURI();
        if (predicate.toLowerCase().endsWith("hasattime")) {
            String object = "";
            if (statement.getObject().isLiteral()) {
                object = statement.getObject().asLiteral().toString();
            } else if (statement.getObject().isURIResource()) {
                object = statement.getObject().asResource().getURI();
            }
            if (tripleMapInstances.containsKey( object)) {
                ArrayList<Statement> instanceTriples = tripleMapInstances.get(object);
                for (int j = 0; j < instanceTriples.size(); j++) {
                    Statement timeStatement = instanceTriples.get(j);
                    /**    WHAT TO DO WITH PERIODS????
                     *             time:hasBeginning  <http://www.newsreader-project.eu/time/20100125> ;
                     time:hasEnd        <http://www.newsreader-project.eu/time/20100125> .

                     */
                    if (timeStatement.getPredicate().getURI().toLowerCase().endsWith("indatetime")
                            ||timeStatement.getPredicate().getURI().toLowerCase().endsWith("hasbeginning")
                            || timeStatement.getPredicate().getURI().toLowerCase().endsWith("hasend")) {
                        if (timeStatement.getObject().isLiteral()) {
                            return timeStatement.getObject().asLiteral().toString();
                        } else if (statement.getObject().isURIResource()) {
                            return timeStatement.getObject().asResource().getURI();
                        }
                    }
                }
            }

        }
    }
    return "NOTIMEANCHOR";
}
 
Example #30
Source File: GetEsoCounts.java    From EventCoreference with Apache License 2.0 5 votes vote down vote up
static void updateFramenNetCounts (Statement statement) {
    String predicate = statement.getPredicate().getURI();
    if (predicate.endsWith("#type")) {
        String object = "";
        if (statement.getObject().isLiteral()) {
            object = statement.getObject().asLiteral().toString();
        } else if (statement.getObject().isURIResource()) {
            object = statement.getObject().asResource().getURI();
        }
        String [] values = object.split(",");
        for (int j = 0; j < values.length; j++) {
            String value = values[j];
            String property = TrigUtil.getNameSpaceString(value);
            if (!property.isEmpty() && !property.equalsIgnoreCase("sem")) {
                value = TrigUtil.getValue(value);
                if (property.equals("fn")) {
                    if (fnCounts.containsKey(value)) {
                        Integer cnts = fnCounts.get(value);
                        cnts++;
                        fnCounts.put(value, cnts);

                    } else {
                        fnCounts.put(value, 1);
                    }
                }
            }
        }
    }
}