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

The following examples show how to use com.hp.hpl.jena.rdf.model.Resource#getProperty() . 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: D2RQAssembler.java    From GeoTriples with Apache License 2.0 6 votes vote down vote up
public Object open(Assembler ignore, Resource description, Mode ignore2) {
	if (!description.hasProperty(D2RQ.mappingFile)) {
		throw new D2RQException("Error in assembler specification " + description + ": missing property d2rq:mappingFile");
	}
	if (!description.getProperty(D2RQ.mappingFile).getObject().isURIResource()) {
		throw new D2RQException("Error in assembler specification " + description + ": value of d2rq:mappingFile must be a URI");
	}
	String mappingFileURI = ((Resource) description.getProperty(D2RQ.mappingFile).getObject()).getURI();
	String resourceBaseURI = null;
	Statement stmt = description.getProperty(D2RQ.resourceBaseURI);
	if (stmt != null) {
		if (!stmt.getObject().isURIResource()) {
			throw new D2RQException("Error in assembler specification " + description + ": value of d2rq:resourceBaseURI must be a URI");
		}
		resourceBaseURI = ((Resource) stmt.getObject()).getURI();
	}
	return new ModelD2RQ(mappingFileURI, resourceBaseURI);
}
 
Example 2
Source File: PageServlet.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
public static Statement getBestLabel(Resource resource) {
	Statement label = resource.getProperty(RDFS.label);
	if (label == null)
		label = resource.getProperty(SKOS.prefLabel);
	if (label == null)
		label = resource.getProperty(DC.title);
	if (label == null)
		label = resource.getProperty(DCTerms.title);
	if (label == null)
		label = resource.getProperty(FOAF.name);
	return label;
}
 
Example 3
Source File: OpenCycOntology.java    From xcurator with Apache License 2.0 5 votes vote down vote up
public String getLabelForResource(String uri) {
    Resource subject = model.createResource(uri);
    Statement stmt = subject.getProperty(RDFS.label);
    if (stmt != null) {
        RDFNode object = stmt.getObject();
        return object == null ? "" : object.asLiteral().getString();
    } else {
        return "";
    }
}
 
Example 4
Source File: ResourceDescriptionServlet.java    From GeoTriples with Apache License 2.0 4 votes vote down vote up
protected void doGet(HttpServletRequest request,
		HttpServletResponse response) throws IOException, ServletException {
	D2RServer server = D2RServer.fromServletContext(getServletContext());
	server.checkMappingFileChanged();
	String relativeResourceURI = request.getRequestURI().substring(
			request.getContextPath().length()
					+ request.getServletPath().length());
	// Some servlet containers keep the leading slash, some don't
	if (!"".equals(relativeResourceURI)
			&& "/".equals(relativeResourceURI.substring(0, 1))) {
		relativeResourceURI = relativeResourceURI.substring(1);
	}
	if (request.getQueryString() != null) {
		relativeResourceURI = relativeResourceURI + "?"
				+ request.getQueryString();
	}

	/* Determine service stem, i.e. vocab/ in /[vocab/]data */
	int servicePos;
	if (-1 == (servicePos = request.getServletPath().indexOf(
			"/" + D2RServer.getDataServiceName())))
		throw new ServletException("Expected to find service path /"
				+ D2RServer.getDataServiceName());
	String serviceStem = request.getServletPath().substring(1,
			servicePos + 1);

	String resourceURI = RequestParamHandler
			.removeOutputRequestParam(server.resourceBaseURI(serviceStem)
					+ relativeResourceURI);
	String documentURL = server.dataURL(serviceStem, relativeResourceURI);

	String pageURL = server.pageURL(serviceStem, relativeResourceURI);

	String sparqlQuery = "DESCRIBE <" + resourceURI + ">";
	QueryExecution qe = QueryExecutionFactory.create(sparqlQuery,
			server.dataset());
	if (server.getConfig().getPageTimeout() > 0) {
		qe.setTimeout(Math.round(server.getConfig().getPageTimeout() * 1000));
	}
	Model description = qe.execDescribe();
	qe.close();
	
	if (description.size() == 0) {
		response.sendError(404);
	}
	if (description.qnameFor(FOAF.primaryTopic.getURI()) == null
			&& description.getNsPrefixURI("foaf") == null) {
		description.setNsPrefix("foaf", FOAF.NS);
	}
	Resource resource = description.getResource(resourceURI);

	Resource document = description.getResource(documentURL);
	document.addProperty(FOAF.primaryTopic, resource);

	Statement label = resource.getProperty(RDFS.label);
	if (label != null) {
		document.addProperty(RDFS.label,
				"RDF Description of " + label.getString());
	}
	server.addDocumentMetadata(description, document);
	if (server.getConfig().serveMetadata()) {
		// add document metadata from template
		Model resourceMetadataTemplate = server.getConfig().getResourceMetadataTemplate(
				server, getServletContext());
		MetadataCreator resourceMetadataCreator = new MetadataCreator(
				server, resourceMetadataTemplate);
		description.add(resourceMetadataCreator.addMetadataFromTemplate(
				resourceURI, documentURL, pageURL));
		
		Map<String, String> descPrefixes = description.getNsPrefixMap();
		descPrefixes.putAll(resourceMetadataTemplate.getNsPrefixMap());
		description.setNsPrefixes(descPrefixes);
	}
	// TODO: Add a Content-Location header
	new ModelResponse(description, request, response).serve();
}
 
Example 5
Source File: R2RMLReader.java    From GeoTriples with Apache License 2.0 2 votes vote down vote up
private TermMap createTransformationValuedTermMap(Resource r) {
	TransformationValuedTermMap result = new TransformationValuedTermMap();
	result.setFunction(ConstantIRI.create(getString(r, RRX.function)));
	
	
	List<TermMap> arguments=new ArrayList<TermMap>();
	//Resource list = getResource(r, RRX.argumentMap);
	
	RDFNode list2 = r.getProperty(RRX.argumentMap).getObject();;
	
	
	
	RDFList rdfList = list2.as( RDFList.class );
       ExtendedIterator<RDFNode> items = rdfList.iterator();
       while ( items.hasNext() ) {
           Resource item = items.next().asResource();            
           if(item.getProperty(RR.constant)!=null)
           {
   			arguments.add(createConstantValuedTermMap(item));
   		}
           if(item.getProperty(RR.column)!=null) {
			arguments.add(createColumnValuedTermMap(item));
		}
		if(item.getProperty(RRX.function)!=null) {
			arguments.add(createTransformationValuedTermMap(item));
		}
		if(item.getProperty(RR.template)!=null) {
			arguments.add(createTemplateValuedTermMap(item));
		}
           
       }
	
	
	
	
	
	
	
	
       
	result.setTermMaps(arguments);
	readColumnOrTemplateValuedTermMap(result, r);
	return result;
}