Java Code Examples for com.hp.hpl.jena.vocabulary.RDF

The following examples show how to use com.hp.hpl.jena.vocabulary.RDF. 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: John_BaseXMLWriter.java    License: Apache License 2.0 6 votes vote down vote up
private void generateDoctypeDeclaration(Model model, PrintWriter pw) {
	String rdfns = RDF.getURI();
	String rdfRDF = model.qnameFor(rdfns + "RDF");
	if (rdfRDF == null) {
		model.setNsPrefix("rdf", rdfns);
		rdfRDF = "rdf:RDF";
	}
	Map<String, String> prefixes = model.getNsPrefixMap();
	pw.print("<!DOCTYPE " + rdfRDF + " [");
	for (Iterator<String> it = prefixes.keySet().iterator(); it.hasNext();) {
		String prefix = it.next();
		if (isPredefinedEntityName(prefix))
			continue;
		pw.print(newline
				+ "  <!ENTITY "
				+ strForPrefix(prefix)
				+ " '"
				+ Util.substituteEntitiesInEntityValue(prefixes.get(prefix))
				+ "'>");
	}
	pw.print("]>" + newline);
}
 
Example 2
Source Project: GeoTriples   Source File: John_Unparser.java    License: Apache License 2.0 6 votes vote down vote up
private boolean hasProperties(Resource r) {
    ExtendedIterator<Statement> ss = listProperties(r);
    if (avoidExplicitReification && // ( r instanceof Statement ) &&
            (!r.isAnon()) && isLocalReference(r)
            && res2statement.containsKey(r)) {
        ss = new MapFilterIterator<Statement, Statement>(new MapFilter<Statement, Statement>() {
            @Override
            public Statement accept(Statement o) {
                Statement s = o;
                Property p = s.getPredicate();
                return ((!p.getNameSpace().equals(rdfns)) || !((RDF.type
                        .equals(p) && s.getObject().equals(RDF.Statement))
                        || RDF.object.equals(p) || RDF.predicate.equals(p) || RDF.subject
                        .equals(p))) ? o : null;
            }
        }, ss);
    }
    try {
        return ss.hasNext();
    } finally {
        ss.close();
    }
}
 
Example 3
Source Project: GeoTriples   Source File: John_Unparser.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @return A statement that is suitable for a typed node construction or
 *         null.
 */
private Statement getType(Resource r) {
    Statement rslt;
    try {
        if (r instanceof Statement) {
            rslt = ((Statement) r).getStatementProperty(RDF.type);
            if (rslt == null || (!rslt.getObject().equals(RDF.Statement)))
                error("Statement type problem");
        } else {
            rslt = r.getRequiredProperty(RDF.type);
        }
    } catch (PropertyNotFoundException rdfe) {
        if (r instanceof Statement)
            error("Statement type problem");
        rslt = null;
    }
    if (rslt == null || isOKType(rslt.getObject()) == -1)
        return null;

    return rslt;
}
 
Example 4
Source Project: GeoTriples   Source File: GeneralMappingStyle.java    License: Apache License 2.0 6 votes vote down vote up
public GeneralMappingStyle(GeneralConnection connection, String baseIRI, String fileName) {
	this.baseIRI = baseIRI;
	this.fileName = fileName;
	if (this.baseIRI.endsWith("/")) {
		this.baseIRI = this.baseIRI.substring(0, this.baseIRI.length()-1);
	}
	this.vocabBaseIRI = this.baseIRI + "ontology#";
	this.geoBaseIRI = this.baseIRI;
	//this.geoBaseIRI = this.baseIRI + "/Geometry";
	if (fileName == null) {
		this.entityBaseIRI = this.baseIRI + "/Feature";
	}
	else {
		this.entityBaseIRI = this.baseIRI + "/" + fileName.substring(0, fileName.lastIndexOf('.'));
	}
	model.setNsPrefix("rdf", RDF.getURI());
	model.setNsPrefix("rdfs", RDFS.getURI());
	model.setNsPrefix("xsd", XSD.getURI());
	model.setNsPrefix("ogc", "http://www.opengis.net/ont/geosparql#");
	model.setNsPrefix("geof", "http://www.opengis.net/def/function/geosparql/");
	model.setNsPrefix("vocab", vocabBaseIRI);
	//model.setNsPrefix("tablename", vocabBaseIRI);
	generator = new GeneralMappingGenerator(this, connection);
}
 
Example 5
Source Project: GeoTriples   Source File: JenaModelExample.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
	// Set up the ModelD2RQ using a mapping file
	ModelD2RQ m = new ModelD2RQ("file:doc/example/mapping-iswc.ttl");
	
	// Find anything with an rdf:type of iswc:InProceedings
	StmtIterator paperIt = m.listStatements(null, RDF.type, ISWC.InProceedings);
	
	// List found papers and print their titles
	while (paperIt.hasNext()) {
		Resource paper = paperIt.nextStatement().getSubject();
		System.out.println("Paper: " + paper.getProperty(DC.title).getString());
		
		// List authors of the paper and print their names
		StmtIterator authorIt = paper.listProperties(DC.creator);
		while (authorIt.hasNext()) {
			Resource author = authorIt.nextStatement().getResource();
			System.out.println("Author: " + author.getProperty(FOAF.name).getString());
		}
		System.out.println();
	}
	m.close();
}
 
Example 6
Source Project: GeoTriples   Source File: VocabularySummarizer.java    License: Apache License 2.0 6 votes vote down vote up
public Collection<Resource> getUndefinedResources(Model model) {
	Set<Resource> result = new HashSet<Resource>();
	StmtIterator it = model.listStatements();
	while (it.hasNext()) {
		Statement stmt = it.nextStatement();
		if (stmt.getSubject().isURIResource()
				&& stmt.getSubject().getURI().startsWith(namespace)
				&& !resources.contains(stmt.getSubject())) {
			result.add(stmt.getSubject());
		}
		if (stmt.getPredicate().equals(RDF.type)) continue;
		if (stmt.getObject().isURIResource()
				&& stmt.getResource().getURI().startsWith(namespace)
				&& !resources.contains(stmt.getResource())) {
			result.add(stmt.getResource());
		}
	}
	return result;
}
 
Example 7
Source Project: GeoTriples   Source File: D2RQMappingStyle.java    License: Apache License 2.0 6 votes vote down vote up
public D2RQMappingStyle(SQLConnection connection, String baseIRI, String fileName) {
	this.baseIRI = baseIRI;
	if (this.baseIRI.endsWith("/")) {
		this.baseIRI = this.baseIRI.substring(0, this.baseIRI.length()-1);
	}
	this.vocabBaseIRI = this.baseIRI + "ontology#";
	this.geoBaseIRI = this.baseIRI;
	this.entityBaseIRI = this.baseIRI;
	model.setNsPrefix("rdf", RDF.getURI());
	model.setNsPrefix("rdfs", RDFS.getURI());
	model.setNsPrefix("xsd", XSD.getURI());
	model.setNsPrefix("ogc", "http://www.opengis.net/ont/geosparql#");
	model.setNsPrefix("geof", "http://www.opengis.net/def/function/geosparql/");
	model.setNsPrefix("vocab", vocabBaseIRI);
	generator = new MappingGenerator(this, connection);
	generator.setGenerateLabelBridges(false);
	generator.setHandleLinkTables(true);
	generator.setGenerateDefinitionLabels(false);
	generator.setServeVocabulary(true);
	generator.setSkipForeignKeyTargetColumns(true);
	generator.setUseUniqueKeysAsEntityID(true);
}
 
Example 8
@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 9
@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 10
@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 11
Source Project: Benchmark   Source File: DataWrapper.java    License: 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 12
Source Project: Benchmark   Source File: DataWrapper.java    License: 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 13
Source Project: Benchmark   Source File: DataWrapper.java    License: 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 14
@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 15
@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 16
@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 17
Source Project: Benchmark   Source File: RDFFileManager.java    License: 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 18
Source Project: Benchmark   Source File: RDFFileManager.java    License: GNU General Public License v3.0 6 votes vote down vote up
private static Resource createTrafficLocation(Model m, EventDeclaration ed) {
	Resource foi = m.createResource(defaultPrefix + "FoI-" + UUID.randomUUID());
	foi.addProperty(RDF.type, m.createResource(ssnPrefix + "FeatureOfInterest"));
	Resource firstNode = m.createResource();
	firstNode.addProperty(RDF.type, m.createResource(ctPrefix + "Node"));
	foi.addProperty(m.createProperty(ctPrefix + "hasFirstNode"), firstNode);
	firstNode.addLiteral(m.createProperty(ctPrefix + "hasStreetNumber"),
			((TrafficReportService) ed).getNode1StreetNo());
	firstNode.addLiteral(m.createProperty(ctPrefix + "hasStreet"), ((TrafficReportService) ed).getNode1Street());
	firstNode.addLiteral(m.createProperty(ctPrefix + "hasCity"), ((TrafficReportService) ed).getNode1City());
	firstNode.addLiteral(m.createProperty(ctPrefix + "hasLatitude"), ((TrafficReportService) ed).getNode1Lat());
	firstNode.addLiteral(m.createProperty(ctPrefix + "hasLongtitude"), ((TrafficReportService) ed).getNode1Lon());
	firstNode.addLiteral(m.createProperty(ctPrefix + "hasNodeName"), ((TrafficReportService) ed).getNode1Name());

	Resource secNode = m.createResource();
	secNode.addProperty(RDF.type, ctPrefix + "Node");
	foi.addProperty(m.createProperty(ctPrefix + "hasSecondNode"), secNode);
	secNode.addLiteral(m.createProperty(ctPrefix + "hasStreetNumber"),
			((TrafficReportService) ed).getNode2StreetNo());
	secNode.addLiteral(m.createProperty(ctPrefix + "hasStreet"), ((TrafficReportService) ed).getNode2Street());
	secNode.addLiteral(m.createProperty(ctPrefix + "hasCity"), ((TrafficReportService) ed).getNode2City());
	secNode.addLiteral(m.createProperty(ctPrefix + "hasLatitude"), ((TrafficReportService) ed).getNode2Lat());
	secNode.addLiteral(m.createProperty(ctPrefix + "hasLongtitude"), ((TrafficReportService) ed).getNode2Lon());
	secNode.addLiteral(m.createProperty(ctPrefix + "hasNodeName"), ((TrafficReportService) ed).getNode2Name());
	return foi;
}
 
Example 19
Source Project: EventCoreference   Source File: SemTime.java    License: 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 20
Source Project: anno4j   Source File: IsATestEvaluator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Var evaluate(NodeSelector nodeSelector, ElementGroup elementGroup, Var var, LDPathEvaluatorConfiguration evaluatorConfiguration) {
    TestingSelector testingSelector = (TestingSelector) nodeSelector;
    NodeTest nodeTest = testingSelector.getTest();
    Var delVar = LDPathEvaluator.evaluate(testingSelector.getDelegate(), elementGroup, var, evaluatorConfiguration);

    IsATest isATest = (IsATest) nodeTest;
    elementGroup.addTriplePattern(new Triple(delVar.asNode(), RDF.type.asNode(), NodeFactory.createURI(isATest.getPathExpression(new SesameValueBackend()).replace("<", "").replace(">", "").replaceFirst("is-a ", ""))));

    return delVar;
}
 
Example 21
Source Project: anno4j   Source File: IsATestEvaluator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Expr evaluate(NodeTest nodeTest, ElementGroup elementGroup, Var var, LDPathEvaluatorConfiguration evaluatorConfiguration) {
    IsATest isATest = (IsATest) nodeTest;
    Var tmpVar = Var.alloc(Var.alloc(VarIDGenerator.createID()));
    elementGroup.addTriplePattern(new Triple(var.asNode(), RDF.type.asNode(), tmpVar.asNode()));
    return new E_Equals(new ExprVar(tmpVar.asNode()), new NodeValueNode(NodeFactory.createURI(isATest.getPathExpression(new SesameValueBackend()).replace("<", "").replace(">", "").replaceFirst("is-a ", ""))));
}
 
Example 22
Source Project: anno4j   Source File: EvalQuery.java    License: Apache License 2.0 5 votes vote down vote up
public static <T extends ResourceObject> Query evaluate(QueryServiceConfiguration queryServiceDTO, URI rootType) throws ParseException {

        Query query = QueryFactory.make();
        query.setQuerySelectType();

        ElementGroup elementGroup = new ElementGroup();

        Var objectVar = Var.alloc("root");

        // Creating and adding the first triple - could be something like: "?objectVar rdf:type oa:Annotation
        Triple t1 = new Triple(objectVar, RDF.type.asNode(), NodeFactory.createURI(rootType.toString()));
        elementGroup.addTriplePattern(t1);

        // Evaluating the criteria
        for (Criteria c : queryServiceDTO.getCriteria()) {
            SesameValueBackend backend = new SesameValueBackend();

            LdPathParser parser = new LdPathParser(backend, queryServiceDTO.getConfiguration(), new StringReader(c.getLdpath()));
            Var var = LDPathEvaluator.evaluate(parser.parseSelector(queryServiceDTO.getPrefixes()), elementGroup, objectVar, queryServiceDTO.getEvaluatorConfiguration());

            if (c.getConstraint() != null) {
                String resolvedConstraint = resolveConstraintPrefix(c.getConstraint(), queryServiceDTO, parser);
                EvalComparison.evaluate(elementGroup, c, var, resolvedConstraint);
            }
        }

        // Adding all generated patterns to the query object
        query.setQueryPattern(elementGroup);

        // Choose what we want so select - SELECT ?annotation in this case
        query.addResultVar(objectVar);

        // Setting the default prefixes, like rdf: or dc:
        query.getPrefixMapping().setNsPrefixes(queryServiceDTO.getPrefixes());

        return query;
    }
 
Example 23
Source Project: GeoTriples   Source File: GeneralResourceCollection.java    License: Apache License 2.0 5 votes vote down vote up
private Collection<GeneralTripleRelation> filterTripleRelations(Collection<GeneralTripleRelation> entityDescription) {
	List<GeneralTripleRelation> result = new ArrayList<GeneralTripleRelation>();
	for (GeneralTripleRelation triples: entityDescription) {
		triples = triples.orderBy(TripleRelation.SUBJECT, true);
		if (triples.selectTriple(new Triple(Node.ANY, RDF.Nodes.type, Node.ANY)) != null) {
			result.add(triples);
		}
		// TODO: The list of label properties is redundantly specified in PageServlet
		if (triples.selectTriple(new Triple(Node.ANY, RDFS.label.asNode(), Node.ANY)) != null) {
			result.add(triples);
		} else if (triples.selectTriple(new Triple(Node.ANY, SKOS.prefLabel.asNode(), Node.ANY)) != null) {
			result.add(triples);
		} else if (triples.selectTriple(new Triple(Node.ANY, DC.title.asNode(), Node.ANY)) != null) {
			result.add(triples);					
		} else if (triples.selectTriple(new Triple(Node.ANY, DCTerms.title.asNode(), Node.ANY)) != null) {
			result.add(triples);					
		} else if (triples.selectTriple(new Triple(Node.ANY, FOAF.name.asNode(), Node.ANY)) != null) {
			result.add(triples);					
		}
	}
	if (result.isEmpty()) {
		result.add(new GeneralTripleRelation(connection, entityTable, 
				entityMaker, 
				new FixedNodeMaker(RDF.type.asNode()), 
				new FixedNodeMaker(RDFS.Resource.asNode())));
	}
	return result;
}
 
Example 24
Source Project: GeoTriples   Source File: John_BaseXMLWriter.java    License: Apache License 2.0 5 votes vote down vote up
void setupMaps() {
	nameSpaces.set11(RDF.getURI(), "rdf");
	nameSpaces.set11(RDFS.getURI(), "rdfs");
	nameSpaces.set11(DC.getURI(), "dc");
	nameSpaces.set11(RSS.getURI(), "rss");
	nameSpaces.set11("http://www.daml.org/2001/03/daml+oil.daml#", "daml");
	nameSpaces.set11(VCARD.getURI(), "vcard");
	nameSpaces.set11("http://www.w3.org/2002/07/owl#", "owl");
}
 
Example 25
Source Project: GeoTriples   Source File: John_BaseXMLWriter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param baseModel
 * @param model
 */
private void setupNamespaces(Model baseModel, Model model) {
	this.namespacesNeeded = new HashSet<String>();
	this.ns = null;
	this.modelPrefixMapping = baseModel;
	primeNamespace(baseModel);
	addNameSpace(RDF.getURI());
	addNameSpaces(model);
	jenaPrefixCount = 0;
}
 
Example 26
Source Project: GeoTriples   Source File: John_Unparser.java    License: Apache License 2.0 5 votes vote down vote up
private void wPropAttr(Property p, RDFNode n) {
    tab();
    if (p.equals(RDF.type))
        wTypeAttr((Resource) n);
    else
        wPropAttrString(p, (Literal) n);
}
 
Example 27
Source Project: GeoTriples   Source File: John_Unparser.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Name space stuff.
 */
private void addTypeNameSpaces() {
    NodeIterator nn = model.listObjectsOfProperty(RDF.type);
    try {
        while (nn.hasNext()) {
            RDFNode obj = nn.nextNode();
            int split = isOKType(obj);
            if (split != -1)
                prettyWriter.addNameSpace(((Resource) obj).getURI()
                        .substring(0, split));
        }
    } finally {
        nn.close();
    }
}
 
Example 28
Source Project: GeoTriples   Source File: John_Unparser.java    License: Apache License 2.0 5 votes vote down vote up
private Statement[] reification(Statement s) {
    Model m = s.getModel();
    Resource r = statement2res.get(s);
    return new Statement[] { m.createStatement(r, RDF.type, RDF.Statement),
            m.createStatement(r, RDF.subject, s.getSubject()),
            m.createStatement(r, RDF.predicate, s.getPredicate()),
            m.createStatement(r, RDF.object, s.getObject()) };
}
 
Example 29
Source Project: GeoTriples   Source File: VocabularySummarizer.java    License: Apache License 2.0 5 votes vote down vote up
public Collection<Resource> getUndefinedClasses(Model model) {
	Set<Resource> result = new HashSet<Resource>();
	StmtIterator it = model.listStatements(null, RDF.type, (RDFNode) null);
	while (it.hasNext()) {
		Statement stmt = it.nextStatement();
		if (stmt.getObject().isURIResource()
				&& stmt.getResource().getURI().startsWith(namespace)
				&& !classes.contains(stmt.getObject())) {
			result.add(stmt.getResource());
		}
	}
	return result;
}
 
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;
}