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

The following examples show how to use com.hp.hpl.jena.rdf.model.Statement. These examples are extracted from open source projects. 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 Project: GeoTriples   Source File: WP2N3JenaWriterPP.java    License: 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 2
Source Project: EventCoreference   Source File: GetEntityCounts.java    License: 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 3
Source Project: GeoTriples   Source File: GeneralR2RMLCompiler.java    License: 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 4
Source Project: EventCoreference   Source File: JsonFromRdf.java    License: 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 5
Source Project: GeoTriples   Source File: R2RMLReader.java    License: 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 6
@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 7
@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 8
Source Project: EventCoreference   Source File: TrigUtil.java    License: 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 9
@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 10
Source Project: EventCoreference   Source File: JsonFromRdf.java    License: 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 11
@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 12
Source Project: EventCoreference   Source File: JsonFromRdf.java    License: 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 13
Source Project: EventCoreference   Source File: TrigUtil.java    License: 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 14
Source Project: EventCoreference   Source File: TrigStats.java    License: 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 15
Source Project: EventCoreference   Source File: JsonFromRdf.java    License: 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 16
Source Project: wandora   Source File: SparqlExtractor.java    License: 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 17
Source Project: r2rml-parser   Source File: ComplianceTests.java    License: 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 18
Source Project: LodView   Source File: SPARQLEndPoint.java    License: 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 19
Source Project: EventCoreference   Source File: TrigToJsonTimeLine.java    License: 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 20
Source Project: marklogic-contentpump   Source File: RDFReader.java    License: Apache License 2.0 5 votes vote down vote up
public boolean nextInMemoryTripleKeyValue() throws IOException, InterruptedException {
    if(statementIter == null) return false;
    if (!statementIter.hasNext()) {
        hasNext = false;
        return false;
    }
    setKey();
    write("<sem:triples xmlns:sem='http://marklogic.com/semantics'>\n");
    write("<sem:origin>" + origFn + "</sem:origin>\n");
    int max = MAXTRIPLESPERDOCUMENT;
    while (max > 0 && statementIter.hasNext()) {
        Statement stmt = statementIter.nextStatement();
        write("<sem:triple>");
        write(subject(stmt.getSubject()));
        write(predicate(stmt.getPredicate()));
        write(object(stmt.getObject()));
        write("</sem:triple>\n");
        notifyUser();
        max--;
    }
    write("</sem:triples>\n");

    if (!statementIter.hasNext()) {
        pos = 1;
    }

    writeValue();
    return true;
}
 
Example 21
Source Project: marklogic-contentpump   Source File: RDFReader.java    License: Apache License 2.0 5 votes vote down vote up
public boolean nextInMemoryQuadKeyValueWithCollections() throws IOException, InterruptedException {
    if(statementIter == null) return false;
    while (!statementIter.hasNext()) {
        if (graphNameIter.hasNext()) {
            collection = graphNameIter.next();
            statementIter = dataset.getNamedModel(collection).listStatements();
        } else {
            hasNext = false;
            collection = null;
            return false;
        }
    }
    setKey();
    write("<sem:triples xmlns:sem='http://marklogic.com/semantics'>");
    int max = MAXTRIPLESPERDOCUMENT;
    while (max > 0 && statementIter.hasNext()) {
        Statement stmt = statementIter.nextStatement();
        write("<sem:triple>");
        write(subject(stmt.getSubject()));
        write(predicate(stmt.getPredicate()));
        write(object(stmt.getObject()));
        write("</sem:triple>");
        max--;
        notifyUser();
    }
    write("</sem:triples>\n");

    if (!statementIter.hasNext()) {
        pos = 1;
    }

    writeValue(collection);
    return true;
}
 
Example 22
Source Project: EventCoreference   Source File: JsonFromRdf.java    License: Apache License 2.0 5 votes vote down vote up
static boolean matchEventType (ArrayList<Statement> statements, String eventTypes) throws JSONException {

        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")) {
                        if (eventTypes.toLowerCase().indexOf(property)>-1) {
                           return true;
                        }
                    }
                }
            }
        }
        return false;
    }
 
Example 23
/**
 * Retrieve the dhus system supported items for file scanning processing.
 * Is considered supported all classes having
 * <code>http://www.gael.fr/dhus#metadataExtractor</code> property
 * connection.
 * @return the list of supported class names.
 */
public static synchronized String[] getDefaultCortexSupport ()
{
   DrbCortexModel model;
   try
   {
      model = DrbCortexModel.getDefaultModel ();
   }
   catch (IOException e)
   {
      throw new UnsupportedOperationException (
         "Drb cortex not properly initialized.");
   }

   ExtendedIterator it=model.getCortexModel ().getOntModel ().listClasses ();
   List<String>list = new ArrayList<String> ();

   while (it.hasNext ())
   {
      OntClass cl = (OntClass)it.next ();

      OntProperty metadata_extractor_p = cl.getOntModel().getOntProperty(
            "http://www.gael.fr/dhus#support");

      StmtIterator properties = cl.listProperties (metadata_extractor_p);
      while (properties.hasNext ())
      {
         Statement stmt = properties.nextStatement ();
         LOGGER.debug ("Scanner Support Added for " +
            stmt.getSubject ().toString ());
         list.add (stmt.getSubject ().toString ());
      }
   }
   return list.toArray (new String[list.size ()]);
}
 
Example 24
Source Project: anno4j   Source File: JenaSesameUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Convert the Sesame Graph to a Jena Model
 * @param theGraph the Graph to convert
 * @return the set of statements in the Sesame Graph converted and saved in a Jena Model
 */
public static Model asJenaModel(Graph theGraph) {
    Model aModel = ModelFactory.createDefaultModel();

    for (final org.openrdf.model.Statement aStmt : theGraph) {
        aModel.add(asJenaStatement(aStmt));
    }

    return aModel;
}
 
Example 25
Source Project: EventCoreference   Source File: TrigUtil.java    License: Apache License 2.0 5 votes vote down vote up
static public boolean isGafTriple(Statement s) {
    if (s.getPredicate().toString().toLowerCase().contains("#denotedby")) {
        return true;
    }
    else {
        return false;
    }
}
 
Example 26
Source Project: EventCoreference   Source File: TrigUtil.java    License: Apache License 2.0 5 votes vote down vote up
static public String triplesToString (ArrayList<Statement> statements) {
    String str = "";
    String eventLabels = "";
    String roles = "";
    String gaf = "";
    for (int i = 0; i < statements.size(); i++) {
        Statement statement = statements.get(i);
        if (statement.getPredicate().toString().toLowerCase().contains("#label")) {
            if (!eventLabels.isEmpty()) {
                eventLabels += ",";
            }
            eventLabels += getObjectValue(statement);
        } else {
            if (isGafTriple(statement)) {
                if (!gaf.isEmpty()) {
                    gaf+= "; ";
                }
                gaf += getMention(statement.getObject().toString());
            }
            else {
                roles += "\t" + getValue(statement.getPredicate().toString())
                        + ":" + getObjectValue(statement);
            }
        }
    }
    if (!roles.isEmpty()) {
        str = eventLabels + roles + "\t" + gaf + "\n";
    }
    return str;
}
 
Example 27
Source Project: EventCoreference   Source File: TrigUtil.java    License: Apache License 2.0 5 votes vote down vote up
static public boolean validTriple (Statement s) {
    if (s.getPredicate().toString().toLowerCase().contains("propbank")) {
        return true;
    }/*
    else if (s.getPredicate().toString().toLowerCase().contains("hastime")) {
        return true;
    }*/
    else if (s.getPredicate().toString().toLowerCase().contains("#label")) {
        return true;
    }
    else if (s.getPredicate().toString().toLowerCase().contains("#denotedby")) {
        return true;
    }/*
    else if (s.getPredicate().toString().toLowerCase().contains("#type") &&
             s.getObject().toString().toLowerCase().contains("framenet")) {
        return true;
    }*/
    /*else if (s.getPredicate().toString().toLowerCase().contains("#type") &&
             s.getObject().toString().toLowerCase().contains("domain-ontology")) {
        return true;
    }*/
    else {
      //  System.out.println("s.getPredicate() = " + s.getPredicate());

        return false;
    }
}
 
Example 28
Source Project: GeoTriples   Source File: VocabularySummarizer.java    License: Apache License 2.0 5 votes vote down vote up
public Collection<Property> getUndefinedProperties(Model model) {
	Set<Property> result = new HashSet<Property>();
	StmtIterator it = model.listStatements();
	while (it.hasNext()) {
		Statement stmt = it.nextStatement();
		if (stmt.getPredicate().getURI().startsWith(namespace)
				&& !properties.contains(stmt.getPredicate())) {
			result.add(stmt.getPredicate());
		}
	}
	return result;
}
 
Example 29
Source Project: EventCoreference   Source File: JsonFromRdf.java    License: Apache License 2.0 5 votes vote down vote up
static JSONObject getTopicsJSONObjectFromInstanceStatement (ArrayList<Statement> statements) throws JSONException {

        // skos:related    "air transport" , "aeronautical industry" , "transport regulations" , "air law" , "carrier" , "air safety" .
        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();
            // System.out.println("predicate = " + predicate);
            if ((predicate.toLowerCase().endsWith("skos/core#relatedmatch")) ||
                    (predicate.toLowerCase().endsWith("skos/core#related"))) {
                // System.out.println("predicate = " + predicate);
                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("topics", value);
                    }
                }
            }
        }
        return jsonClassesObject;
    }
 
Example 30
Source Project: GeoTriples   Source File: VocabularySummarizer.java    License: Apache License 2.0 5 votes vote down vote up
public boolean usesVocabulary(Model model) {
	StmtIterator it = model.listStatements();
	while (it.hasNext()) {
		Statement stmt = it.nextStatement();
		if (stmt.getPredicate().getURI().startsWith(namespace)) {
			return true;
		}
		if (stmt.getPredicate().equals(RDF.type) && stmt.getResource().getURI().startsWith(namespace)) {
			return true;
		}
	}
	return false;
}