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

The following are top voted examples for showing how to use com.hp.hpl.jena.rdf.model.Resource. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: harvesters   File: Queries.java   Source Code and License 7 votes vote down vote up
public Resource getAgentUri(VirtGraph graphOrgs, String vatId) {
	
	Resource agentUri = null;
	
	String queryUri = "PREFIX gr: <http://purl.org/goodrelations/v1#> " +
				"SELECT ?org ?vatId " +
				"FROM <" + QueryConfiguration.queryGraphOrganizations + "> " +
				"WHERE { " +
				"?org gr:vatID ?vatId . " +
				"FILTER ( ?vatId = \"" + vatId + "\"^^<http://www.w3.org/2001/XMLSchema#string> ) " +
				"}";

	VirtuosoQueryExecution vqeUri = VirtuosoQueryExecutionFactory.create(queryUri, graphOrgs);		
	ResultSet resultsUri = vqeUri.execSelect();
	
	if (resultsUri.hasNext()) {
		QuerySolution result = resultsUri.nextSolution();
		agentUri = result.getResource("org");
	}
	
	vqeUri.close();
	
	return agentUri;
}
 
Example 2
Project: r2rml-kit   File: MappingValidator.java   Source Code and License 6 votes vote down vote up
private void validateComponentType(Property property, Resource resource, 
		ComponentType... types) {
	if (resource == null) return;
	List<Resource> foundTypes = new ArrayList<Resource>(types.length);
	List<Resource> supportedTypes = new ArrayList<Resource>(types.length);
	for (ComponentType type: types) {
		supportedTypes.add(type.asResource());
		MappingComponent value = mapping.getMappingComponent(resource, type);
		if (value != null) {
			foundTypes.add(type.asResource());
		}
	}
	if (foundTypes.isEmpty()) {
		report.report(Problem.VALUE_NOT_OF_EXPECTED_TYPE, getContextResource(), property, 
				supportedTypes.toArray(new Resource[supportedTypes.size()]));
	} else if (foundTypes.size() > 1) {
		report.report(Problem.CONFLICTING_TYPES, getContextResource(), property, 
				foundTypes.toArray(new Resource[foundTypes.size()]));
	}
}
 
Example 3
Project: r2rml-kit   File: D2RQTarget.java   Source Code and License 6 votes vote down vote up
public void generateEntities(Resource class_, TableName table,
		TemplateValueMaker iriTemplate, List<Identifier> blankNodeColumns) {
	log.info("Generating d2rq:ClassMap instance for table " + Microsyntax.toString(table));
	ClassMap result = getClassMap(table);
	result.setComment("Table " + Microsyntax.toString(table));
	if (iriTemplate == null) {
		result.setBNodeIdColumns(table.qualifyIdentifiers(blankNodeColumns));
	} else {
		if (iriTemplate.columns().length == 0) {
			result.setComment(result.getComment() + 
					"\nNOTE: Sorry, I don't know which columns to put into the d2rq:uriPattern\n" +
					"because the table doesn't have a primary key. Please specify it manually.");
		}
		result.setURIPattern(Microsyntax.toString(iriTemplate));
	}
	if (class_ != null) {
		result.addClass(class_);
		if (generateDefinitionLabels) {
			result.addDefinitionLabel(model.createLiteral(
					Microsyntax.toString(table)));
		}
	}
}
 
Example 4
Project: harvesters   File: MonthlyRdfActions.java   Source Code and License 6 votes vote down vote up
/**
    * Add to the model the decision statuses.
    * 
    * @param Model the model we are currently working with
    */
public void addDecisionStatusToModel(Model model) {
	
	List<String> statusesList = Arrays.asList("Published", "Pending_Revocation", "Revoked", "Submitted");
	
	for (String status : statusesList) {
		String[] statusDtls = hm.findDecisionStatusIndividual(status);
		/** statusResource **/
		Resource statusResource = model.createResource(statusDtls[0], Ontology.decisionStatusResource);
		model.createResource(statusDtls[0], Ontology.conceptResource);
		/** configure prefLabel **/
		statusResource.addProperty(Ontology.prefLabel, statusDtls[1], "el");
		statusResource.addProperty(Ontology.prefLabel, statusDtls[2], "en");
       }
	
}
 
Example 5
Project: harvesters   File: Queries.java   Source Code and License 6 votes vote down vote up
public Resource getAgentUriNoVat(VirtGraph graphOrgs, String vatId) {
	
	Resource agentUri = null;
	
	String queryUri = "PREFIX gr: <http://purl.org/goodrelations/v1#> " +
				"SELECT DISTINCT ?org " +
				"FROM <" + QueryConfiguration.queryGraphOrganizations + "> " +
				"WHERE { " +
				"?org rdf:type foaf:Organization . " +
				"FILTER (STR(?org) = \"http://linkedeconomy.org/resource/Organization/" + vatId + "\") . " +
				"}";

	VirtuosoQueryExecution vqeUri = VirtuosoQueryExecutionFactory.create(queryUri, graphOrgs);		
	ResultSet resultsUri = vqeUri.execSelect();
	
	if (resultsUri.hasNext()) {
		QuerySolution result = resultsUri.nextSolution();
		agentUri = result.getResource("org");
	}
	
	vqeUri.close();
	
	return agentUri;
}
 
Example 6
Project: c4a_data_repository   File: D2RQAssembler.java   Source Code and License 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, null, resourceBaseURI);
}
 
Example 7
Project: harvesters   File: MonthlyRdfActions.java   Source Code and License 6 votes vote down vote up
/**
 * Add to the model the decision statuses.
 * 
 * @param Model
 *            the model we are currently working with
 */
public void addDecisionStatusToModel(Model model) {

	List<String> statusesList = Arrays.asList("Published", "Pending_Revocation", "Revoked", "Submitted");

	for (String status : statusesList) {
		String[] statusDtls = hm.findDecisionStatusIndividual(status);
		/** statusResource **/
		Resource statusResource = model.createResource(statusDtls[0], Ontology.decisionStatusResource);
		model.createResource(statusDtls[0], Ontology.conceptResource);
		/** configure prefLabel **/
		statusResource.addProperty(Ontology.prefLabel, statusDtls[1], "el");
		statusResource.addProperty(Ontology.prefLabel, statusDtls[2], "en");
	}

}
 
Example 8
Project: harvesters   File: MonthlyRdfActions.java   Source Code and License 6 votes vote down vote up
/**
 * Add to the model the Regular Acts.
 * 
 * @param Model
 *            the model we are currently working with
 */
public void addKanonistikiToModel(Model model) {

	List<String> regularList = Arrays.asList("Υπουργική Απόφαση",
			"Πράξη Γενικού Γραμματέα Αποκεντρωμένης Διοίκησης", "Πράξη Οργάνου Διοίκησης Ν.Π.Δ.Δ.",
			"Πράξη Οργάνου Διοίκησης ΟΤΑ Α’ και Β’ Βαθμού (και εποπτευόμενων φορέων τους)",
			"Λοιπές Κανονιστικές Πράξεις");

	for (String regular : regularList) {
		String[] regularDtls = hm.findKanonistikiIndividual(regular);
		/** regulatoryResource **/
		Resource regularResource = model.createResource(regularDtls[0], Ontology.regulatoryActResource);
		model.createResource(regularDtls[0], Ontology.conceptResource);
		/** configure prefLabel **/
		regularResource.addProperty(Ontology.prefLabel, regularDtls[1], "el");
		regularResource.addProperty(Ontology.prefLabel, regularDtls[2], "en");
	}

}
 
Example 9
Project: harvesters   File: MonthlyRdfActions.java   Source Code and License 6 votes vote down vote up
/**
 * Add to the model the Time Period.
 * 
 * @param Model
 *            the model we are currently working with
 */
public void addTimePeriodToModel(Model model) {

	List<String> timeList = Arrays.asList("Έτος", "ΝΟΕΜΒΡΙΟΣ", "ΟΚΤΩΒΡΙΟΣ", "Τρίμηνο");

	for (String time : timeList) {
		String[] timeDtls = hm.findTimePeriodIndividual(time);
		/** timeResource **/
		Resource timeResource = model.createResource(timeDtls[0], Ontology.timeResource);
		model.createResource(timeDtls[0], Ontology.conceptResource);
		/** configure prefLabel **/
		timeResource.addProperty(Ontology.prefLabel, timeDtls[1], "el");
		timeResource.addProperty(Ontology.prefLabel, timeDtls[2], "en");
	}

}
 
Example 10
Project: c4a_data_repository   File: ClassMapServlet.java   Source Code and License 6 votes vote down vote up
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	D2RServer server = D2RServer.fromServletContext(getServletContext());
	server.checkMappingFileChanged();
	if (request.getPathInfo() == null) {
		new ModelResponse(classMapListModel(), request, response).serve();
		return;
	}
	String classMapName = request.getPathInfo().substring(1);
	Model resourceList = getClassMapLister().classMapInventory(classMapName);
	if (resourceList == null) {
		response.sendError(404, "Sorry, class map '" + classMapName + "' not found.");
		return;
	}
   	Resource classMap = resourceList.getResource(server.baseURI() + "all/" + classMapName);
   	Resource directory = resourceList.createResource(server.baseURI() + "all");
   	classMap.addProperty(RDFS.seeAlso, directory);
   	classMap.addProperty(RDFS.label, "List of all instances: " + classMapName);
   	directory.addProperty(RDFS.label, "D2R Server contents");
   	server.addDocumentMetadata(resourceList, classMap);
	new ModelResponse(resourceList, request, response).serve();
}
 
Example 11
Project: harvesters   File: MonthlyRdfActions.java   Source Code and License 6 votes vote down vote up
/**
 * Add to the model the budget types.
 * 
 * @param Model
 *            the model we are currently working with
 */
public void addBudgetTypeToModel(Model model) {

	List<String> budgetTypeList = Arrays.asList("Τακτικός Προϋπολογισμός", "Πρόγραμμα Δημοσίων Επενδύσεων",
			"Ίδια Έσοδα", "Συγχρηματοδοτούμενο Έργο");

	for (String budgetType : budgetTypeList) {
		String[] budgetDtls = hm.findBudgetTypeIndividual(budgetType);
		/** statusResource **/
		Resource statusResource = model.createResource(budgetDtls[0], Ontology.budgetCategoryResource);
		model.createResource(budgetDtls[0], Ontology.conceptResource);
		/** configure prefLabel **/
		statusResource.addProperty(Ontology.prefLabel, budgetDtls[1], "el");
		statusResource.addProperty(Ontology.prefLabel, budgetDtls[2], "en");
	}

}
 
Example 12
Project: c4a_data_repository   File: ResourceServlet.java   Source Code and License 6 votes vote down vote up
private boolean handleDownload(String resourceURI, HttpServletResponse response, D2RServer server) throws IOException {
	Mapping m = D2RServer.retrieveSystemLoader(getServletContext()).getMapping();
	for (Resource r: m.downloadMapResources()) {
		DownloadMap d = m.downloadMap(r);
		DownloadContentQuery q = new DownloadContentQuery(d, resourceURI);
		if (q.hasContent()) {
			response.setContentType(q.getMediaType() != null ? q.getMediaType() : "application/octet-stream");
			InputStream is = q.getContentStream();
			OutputStream os = response.getOutputStream();
			final byte[] buffer = new byte[0x10000];
			int read;
			do {
				read = is.read(buffer, 0, buffer.length);
				if (read>0) {
					os.write(buffer, 0, read);
				}
			} while (read >= 0);
			is.close();
			q.close();
			return true;
		}
	}
	return false;
}
 
Example 13
Project: r2rml-kit   File: Message.java   Source Code and License 6 votes vote down vote up
/**
 * @param problem
 * @param term
 * @param detailCode Optional error code; indicates a subclass of problems
 * @param details Optional string containing error details
 * @param contextResource May be null
 * @param contextProperty May be null
 */
public Message(Problem problem, MappingTerm term, 
		String detailCode, String details, 
		Resource contextResource, Property contextProperty) {
	this.problem = problem;
	this.subject = contextResource; 
	this.predicates = 
		contextProperty == null 
				? Collections.<Property>emptyList() 
				: Collections.singletonList(contextProperty);
	this.objects = 
		term == null
				? Collections.<RDFNode>emptyList()
				: Collections.<RDFNode>singletonList(ResourceFactory.createPlainLiteral(term.toString()));
	this.detailCode = detailCode;
	this.details = details;
	this.cause = null;
}
 
Example 14
Project: c4a_data_repository   File: MetadataCreator.java   Source Code and License 6 votes vote down vote up
public static File findTemplateFile(D2RServer server,
		Property fileConfigurationProperty) {
	Resource config = server.getConfig().findServerResource();
	if (config == null || !config.hasProperty(fileConfigurationProperty)) {
		return null;
	}
	String metadataTemplate = config.getProperty(fileConfigurationProperty)
			.getString();

	String templatePath;
	if (metadataTemplate.startsWith(File.separator)) {
		templatePath = metadataTemplate;
	} else {
		File mappingFile = new File(server.getConfig()
				.getLocalMappingFilename());
		String folder = mappingFile.getParent();
		if (folder != null) {
			templatePath = folder + File.separator + metadataTemplate;
		} else {
			templatePath = metadataTemplate;
		}

	}
	File f = new File(templatePath);
	return f;
}
 
Example 15
Project: DocIT   File: Tests.java   Source Code and License 5 votes vote down vote up
@Test
public void testContainment() {
	assertTrue(Containment.checkContainment(sampleCompany));
	// add the manager of the research department also to the development
	// department (as employee)
	Resource craig = sampleCompany.getModel()
			.getResource(sampleCompany.NS_COMPANY + "craig");
	sampleCompany.getModel()
			.getResource(sampleCompany.NS_COMPANY + "development")
				.getProperty(sampleCompany.EMPLOYEES)
					.getBag()
						.add(craig);
	
	assertFalse(Containment.checkContainment(sampleCompany));
}
 
Example 16
Project: DocIT   File: Precedence.java   Source Code and License 5 votes vote down vote up
public static boolean checkPrecedence(CompanyModel c) {

		StmtIterator stmtit = c.getModel().listStatements(
				new SimpleSelector(null, c.DEPTS, (RDFNode) null));

		List<Resource> depts = new LinkedList<Resource>();

		while (stmtit.hasNext()) {
			NodeIterator subDeptsIt = stmtit.next().getBag().iterator();
			while (subDeptsIt.hasNext())
				depts.add(subDeptsIt.next().asResource());
		}
		for (Resource dept : depts) {
			// get manager's salary
			double managerSalary = dept.getProperty(c.MANAGER).getProperty(
					c.SALARY).getDouble();
			NodeIterator employeeIt = dept.getProperty(c.EMPLOYEES).getBag()
					.iterator();
			while (employeeIt.hasNext())
				if (!(employeeIt.next().asResource().getProperty(c.SALARY)
						.getDouble() < managerSalary))
					return false;
		}

		return true;

	}
 
Example 17
Project: DocIT   File: Tests.java   Source Code and License 5 votes vote down vote up
@Test
public void testContainment() {
	assertTrue(Containment.checkContainment(sampleCompany));
	// add the manager of the research department also to the development
	// department (as employee)
	Resource craig = sampleCompany.getModel()
			.getResource(sampleCompany.NS_COMPANY + "craig");
	sampleCompany.getModel()
			.getResource(sampleCompany.NS_COMPANY + "development")
				.getProperty(sampleCompany.EMPLOYEES)
					.getBag()
						.add(craig);
	
	assertFalse(Containment.checkContainment(sampleCompany));
}
 
Example 18
Project: ontonethub   File: IndexingJob.java   Source Code and License 5 votes vote down vote up
private List<Statement> getUsage(Property property, Model model){
	
	List<Statement> stmts = new ArrayList<Statement>();
	String sparql = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "
			+ "PREFIX owl: <http://www.w3.org/2002/07/owl#> "
			+ "SELECT DISTINCT ?concept "
			+ "WHERE{"
			+ "  {<" + property.getURI() + "> rdfs:domain ?concept} "
			+ "  UNION "
			+ "  { "
			+ "    ?concept rdfs:subClassOf|owl:equivalentClass ?restriction . "
			+ "    ?restriction a owl:Restriction; "
			+ "      owl:onProperty <" + property.getURI() + "> "
			+ "  } "
			+ "}";
	Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
	QueryExecution queryExecution = QueryExecutionFactory.create(query, model);
	
	ResultSet resultSet = queryExecution.execSelect();
	while(resultSet.hasNext()){
		QuerySolution querySolution = resultSet.next();
		Resource concept = querySolution.getResource("concept");
		
		stmts.add(new StatementImpl(property, usage, concept));
	}
	
	return stmts;
	
}
 
Example 19
Project: ontonethub   File: IndexingJob.java   Source Code and License 5 votes vote down vote up
private List<Statement> getUsage(OntClass ontClass, Model model){
	List<Statement> stmts = new ArrayList<Statement>();
	try{
		String sparql = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "
				+ "PREFIX owl: <http://www.w3.org/2002/07/owl#> "
				+ "SELECT DISTINCT ?concept "
				+ "WHERE{"
				+ "  {?prop rdfs:range <" + ontClass.getURI() + ">; "
				+ "    rdfs:domain ?concept"
				+ "  }"
				+ "  UNION "
				+ "  { "
				+ "    ?concept rdfs:subClassOf|owl:equivalentClass ?restriction . "
				+ "    ?restriction a owl:Restriction; "
				+ "      ?p <" + ontClass.getURI() + "> "
				+ "  } "
				+ "}";
		Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
		QueryExecution queryExecution = QueryExecutionFactory.create(query, model);
		
		ResultSet resultSet = queryExecution.execSelect();
		while(resultSet.hasNext()){
			QuerySolution querySolution = resultSet.next();
			Resource concept = querySolution.getResource("concept");
			
			stmts.add(new StatementImpl(ontClass, usage, concept));
		}
	} catch(Exception e){
		log.error(e.getMessage(), e);
	}
	
	return stmts;
	
}
 
Example 20
Project: c4a_data_repository   File: ParserTest.java   Source Code and License 5 votes vote down vote up
public void testParseTranslationTable() {
	Resource r = addTranslationTableResource();
	addTranslationResource(r, "foo", "bar");
	Mapping mapping = new MapParser(this.model, null).parse();
	TranslationTable table = mapping.translationTable(r);
	assertEquals(1, table.size());
	Translator translator = table.translator();
	assertEquals("bar", translator.toRDFValue("foo"));
}
 
Example 21
Project: c4a_data_repository   File: ConfigLoader.java   Source Code and License 5 votes vote down vote up
protected Resource findDatabaseResource() {
	ResIterator it = this.model.listSubjectsWithProperty(RDF.type,
			D2RQ.Database);
	if (!it.hasNext()) {
		return null;
	}
	return it.nextResource();
}
 
Example 22
Project: c4a_data_repository   File: Mapping.java   Source Code and License 5 votes vote down vote up
/**
 * Helper method to add definitions from a ResourceMap to its underlying resource
 * @param map
 * @param targetResource
 */
private void addDefinitions(ResourceMap map, Resource targetResource) {
	/* Infer rdfs:Class or rdf:Property type */
	Statement s = vocabularyModel.createStatement(targetResource, RDF.type, map instanceof ClassMap ? RDFS.Class : RDF.Property);
	if (!this.vocabularyModel.contains(s))
		this.vocabularyModel.add(s);
	
	/* Apply labels */
	for (Literal propertyLabel: map.getDefinitionLabels()) {
		s = vocabularyModel.createStatement(targetResource, RDFS.label, propertyLabel);
		if (!this.vocabularyModel.contains(s))
			this.vocabularyModel.add(s);
	}

	/* Apply comments */
	for (Literal propertyComment: map.getDefinitionComments()) {
		s = vocabularyModel.createStatement(targetResource, RDFS.comment, propertyComment);
		if (!this.vocabularyModel.contains(s))
			this.vocabularyModel.add(s);
	}
	
	/* Apply additional properties */
	for (Resource additionalProperty: map.getAdditionalDefinitionProperties()) {
		s = vocabularyModel.createStatement(targetResource, 
					(Property)(additionalProperty.getProperty(D2RQ.propertyName).getResource().as(Property.class)),
					additionalProperty.getProperty(D2RQ.propertyValue).getObject());
		if (!this.vocabularyModel.contains(s))
			this.vocabularyModel.add(s);				
	}
}
 
Example 23
Project: c4a_data_repository   File: MapParser.java   Source Code and License 5 votes vote down vote up
private void parseDownloadMaps() {
	Iterator<Individual> it = this.model.listIndividuals(D2RQ.DownloadMap);
	while (it.hasNext()) {
		Resource downloadMapResource = it.next();
		DownloadMap downloadMap = new DownloadMap(downloadMapResource);
		parseResourceMap(downloadMap, downloadMapResource);
		parseDownloadMap(downloadMap, downloadMapResource);
		mapping.addDownloadMap(downloadMap);
	}
}
 
Example 24
Project: c4a_data_repository   File: ConfigLoader.java   Source Code and License 5 votes vote down vote up
protected Resource findServerResource() {
	ResIterator it = this.model.listSubjectsWithProperty(RDF.type,
			D2RConfig.Server);
	if (!it.hasNext()) {
		return null;
	}
	return it.nextResource();
}
 
Example 25
Project: r2rml-kit   File: R2RMLReader.java   Source Code and License 5 votes vote down vote up
private void readTermMap(TermMap termMap, Resource r) {
	termMap.getGraphMaps().addAll(getResources(r, RR.graphMap));
	for (RDFNode graph: getRDFNodes(r, RR.graph)) {
		termMap.getGraphs().add(ConstantShortcut.create(graph));
	}
	for (RDFNode class_: getRDFNodes(r, RR.class_, NodeType.IRI)) {
		termMap.getClasses().add(ConstantIRI.create(class_.asResource()));
	}
	checkTermMapType(r, RR.SubjectMap, RR.subjectMap);
	checkTermMapType(r, RR.PredicateMap, RR.predicateMap);
	checkTermMapType(r, RR.ObjectMap, RR.objectMap);
	checkTermMapType(r, RR.GraphMap, RR.graphMap);
}
 
Example 26
Project: BimSPARQL   File: GeometryTripleExtractor.java   Source Code and License 5 votes vote down vote up
public long geometryTripleCount() throws FileNotFoundException{
	HashSet<Statement> statements=new HashSet<Statement>();
	for (Resource r:getAllGeometricResources()){
		HashSet<Statement> sts=listRelatedStatements(r);
		statements.addAll(sts);
	}
	return statements.size();
}
 
Example 27
Project: r2rml-kit   File: D2RQReaderTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testEmptyTranslationTable() {
	Resource r = addTranslationTableResource();
	Mapping mapping = new D2RQReader(this.model, null).getMapping();
	TranslationTable table = mapping.translationTable(r);
	assertNotNull(table);
	assertEquals(0, table.size());
}
 
Example 28
Project: BimSPARQL   File: RDFWriter.java   Source Code and License 5 votes vote down vote up
private void addListPropertyToGivenEntities(Resource r, OntProperty p, List<Resource> el) throws IOException {
        OntResource range = p.getRange();
        if (range.isClass()) {
            OntResource listrange = getListContentType(range.asClass());

            if (listrange.asClass().hasSuperClass(listModel.getOntClass(getListns() + "OWLList"))) {
//                if (logToFile)
 //                   bw.write("*OK 20*: Handling list of list" + "\r\n");
                listrange = range;
            }
            for (int i = 0; i < el.size(); i++) {
                Resource r1 = el.get(i);
                Resource r2 = ResourceFactory.createResource(getBaseURI() + createLocalName(range.getLocalName() + "_" + IDcounter));
//                Resource r2 = ResourceFactory.createResource(getBaseURI() + range.getLocalName() + "_" + IDcounter); // was
                                                                                                                // listrange
                getRdfWriter().triple(new Triple(r2.asNode(), RDF.type.asNode(), range.asNode()));
 //               if (logToFile)
 //                   bw.write("*OK 14*: added property: " + r2.getLocalName() + " - rdf:type - " + range.getLocalName() + "\r\n");
                IDcounter++;
                Resource r3 = ResourceFactory.createResource(getBaseURI() + createLocalName(range.getLocalName() + "_" + IDcounter));
 //               Resource r3 = ResourceFactory.createResource(getBaseURI() + range.getLocalName() + "_" + IDcounter);

                if (i == 0) {
                    getRdfWriter().triple(new Triple(r.asNode(), p.asNode(), r2.asNode()));
//                    if (logToFile)
//                        bw.write("*OK 15*: added property: " + r.getLocalName() + " - " + p.getLocalName() + " - " + r2.getLocalName() + "\r\n");
                }
                getRdfWriter().triple(new Triple(r2.asNode(), listModel.getOntProperty(getListns() + "hasContents").asNode(), r1.asNode()));
 //               if (logToFile)
//                    bw.write("*OK 16*: added property: " + r2.getLocalName() + " - " + "-hasContents-" + " - " + r1.getLocalName() + "\r\n");

                if (i < el.size() - 1) {
                    getRdfWriter().triple(new Triple(r2.asNode(), listModel.getOntProperty(getListns() + "hasNext").asNode(), r3.asNode()));
//                    if (logToFile)
//                        bw.write("*OK 17*: added property: " + r2.getLocalName() + " - " + "-hasNext-" + " - " + r3.getLocalName() + "\r\n");
                }
            }
        }
    }
 
Example 29
Project: r2rml-kit   File: D2RQReader.java   Source Code and License 5 votes vote down vote up
private void parsePropertyBridges() {
	StmtIterator stmts = this.model.listStatements(null, D2RQ.belongsToClassMap, (RDFNode) null);
	while (stmts.hasNext()) {
		Statement stmt = stmts.nextStatement();
		ClassMap classMap = this.mapping.classMap(stmt.getResource());
		Resource r = stmt.getSubject();
		PropertyBridge bridge = new PropertyBridge(r);
		bridge.setBelongsToClassMap(classMap);
		parseResourceMap(bridge, r);
		parsePropertyBridge(bridge, r);
	}
}
 
Example 30
Project: r2rml-kit   File: OntologyTarget.java   Source Code and License 5 votes vote down vote up
public 	void init(String baseIRI, Resource generatedOntology, 
		boolean serveVocabulary, boolean generateDefinitionLabels) {
	Resource ont = generatedOntology.inModel(model);
	ont.addProperty(RDF.type, OWL.Ontology);
	ont.addProperty(OWL.imports, 
			model.getResource(MappingGenerator.dropTrailingHash(DC.getURI())));
	ont.addProperty(DC.creator, CREATOR);
	this.generatedOntology = ont;
}
 
Example 31
Project: r2rml-kit   File: R2RMLTarget.java   Source Code and License 5 votes vote down vote up
private void addTriplesMap(TableName tableName, LogicalTable table, TermMap subjectMap) {
	Resource tableResource = model.createResource();
	mapping.logicalTables().put(tableResource, table);

	Resource subjectMapResource = model.createResource();
	mapping.termMaps().put(subjectMapResource, subjectMap);

	Resource triplesMapResource = getTriplesMapResource(tableName);
	TriplesMap map = new TriplesMap();
	map.setLogicalTable(tableResource);
	map.setSubjectMap(subjectMapResource);
	mapping.triplesMaps().put(triplesMapResource, map);
}
 
Example 32
Project: ld-sniffer   File: Evaluation.java   Source Code and License 5 votes vote down vote up
public void addDereferenceabilityMeasure(Model model, HttpResponse response) {
    Resource subject = model.createResource(response.getUri());
    try {
        subject.addProperty(URI4URI.host, new URI(response.getUri()).getHost());
    } catch (URISyntaxException e) {
        //We quietly ignore if we can't parse the URI
    }
    Resource measure = addMeasure(model, LDQM.IRIdereferenceability, subject);
    if (response.getStatusCode() >= 200 && response.getStatusCode() < 300 ) {
        measure.addLiteral(DQV.value, model.createTypedLiteral(true, XSDDatatype.XSDboolean));
        measure.addLiteral(EVAL.hasLiteralValue, model.createTypedLiteral(true, XSDDatatype.XSDboolean));
    } else {
        measure.addLiteral(DQV.value, model.createTypedLiteral(false, XSDDatatype.XSDboolean));
        measure.addLiteral(EVAL.hasLiteralValue, model.createTypedLiteral(false, XSDDatatype.XSDboolean));
    }
    Resource request = model.createResource(HTTP.Request);
    measure.addProperty(DCTerms.references, request);
    request.addLiteral(HTTP.methodName, response.getMethod());
    request.addLiteral(HTTP.httpVersion, "1.1");
    request.addLiteral(DCTerms.date, model.createTypedLiteral(DATE_FORMAT.format(response.getDate()),XSDDatatype.XSDdateTime));

    Resource res = model.createResource(HTTP.Response);
    request.addProperty(HTTP.resp, res);
    if (response.getStatusCode() > 0) {
        res.addLiteral(HTTP.statusCodeValue, model.createTypedLiteral(response.getStatusCode(),XSDDatatype.XSDint));
    }
    if (response.getReason() != null){
        res.addLiteral(HTTP.reasonPhrase, response.getReason());
    }
}
 
Example 33
Project: ld-sniffer   File: Evaluation.java   Source Code and License 5 votes vote down vote up
public Resource addMeasure(Model model, Resource metric, Resource subject) {
    Resource measure = model.createResource(LDQM.MEASURE_PREFIX + UUID.randomUUID().toString());
    measure.addProperty(RDF.type, DQV.QualityMeasurement);
    measure.addProperty(RDF.type, DAQ.Observation);
    measure.addProperty(RDF.type, EVAL.QualityValue);
    measure.addProperty(DQV.computedOn, subject);
    measure.addProperty(EVAL.obtainedFrom, evaluation);
    measure.addProperty(PROV.wasGeneratedBy, evaluation);
    measure.addProperty(DQV.isMeasurementOf, metric);
    measure.addProperty(EVAL.forMeasure,  metric);
    measure.addLiteral(DAQ.isEstimate, false);
    return measure;
}
 
Example 34
Project: c4a_data_repository   File: VocabularySummarizerTest.java   Source Code and License 5 votes vote down vote up
public void testFindTwoUndefinedClasses() {
	final Model m = D2RQTestSuite.loadTurtle("vocab/two-undefined-types.ttl");
	VocabularySummarizer vocab = new VocabularySummarizer(D2RQ.class);
	Collection<Resource> expected = new HashSet<Resource>() {{ 
		this.add(m.createResource(D2RQ.NS + "Pint"));
		this.add(m.createResource(D2RQ.NS + "Shot"));
	}};
	assertEquals(expected, vocab.getUndefinedClasses(m));
}
 
Example 35
Project: c4a_data_repository   File: ParserTest.java   Source Code and License 5 votes vote down vote up
private Resource addTranslationResource(Resource table, String dbValue, String rdfValue) {
	Resource translation = this.model.createResource();
	translation.addProperty(D2RQ.databaseValue, dbValue);
	translation.addProperty(D2RQ.rdfValue, rdfValue);
	table.addProperty(D2RQ.translation, translation);
	return translation;
}
 
Example 36
Project: BimSPARQL   File: RDFWriter.java   Source Code and License 5 votes vote down vote up
private void fillProperties(IFCVO ifcLineEntry, Resource r, OntClass cl)
			throws IOException, IfcDataFormatException {
		EntityVO evo = ent.get(ExpressReader.formatClassName(ifcLineEntry.getName()));

		if (evo == null) {
			throw IfcDataFormatException.nonExistingEntity(ifcLineEntry.getName(),
					"#"+ifcLineEntry.getLineNum()+"="+ifcLineEntry.getFullLineAfterNum());

		} else {
			final String subject = createLocalName(evo.getName() + "_" + ifcLineEntry.getLineNum());
			// final String subject = evo.getName() + "_" +
			// ifcLineEntry.getLineNum();
			typeRemembrance = null;
			int attributePointer = 0;
			for (Object o : ifcLineEntry.getObjectList()) {
				if (Character.class.isInstance(o)) {
					if ((Character) o != ',') {
	                        LOGGER.log(Level.WARNING ,"We found a character that is not a comma in line: "+"#"+ifcLineEntry.getLineNum()+"="+ifcLineEntry.getFullLineAfterNum());
					}
				} else if (String.class.isInstance(o)) {
	//				if (logToFile)
	//					bw.write("fillProperties 4 - fillPropertiesHandleStringObject(evo)" + "\r\n");
					attributePointer = fillPropertiesHandleStringObject(r, evo, subject, attributePointer, o,ifcLineEntry);
				} else if (IFCVO.class.isInstance(o)) {
	//				if (logToFile)
	//					bw.write("fillProperties 5 - fillPropertiesHandleIfcObject(evo)" + "\r\n");
					attributePointer = fillPropertiesHandleIfcObject(r, evo, attributePointer, o, ifcLineEntry);
				} else if (LinkedList.class.isInstance(o)) {
	//				if (logToFile)
	//					bw.write("fillProperties 6 - fillPropertiesHandleListObject(evo)" + "\r\n");
					attributePointer = fillPropertiesHandleListObject(r, evo, attributePointer, o,ifcLineEntry);
				}
//				if (logToFile)
//					bw.flush();
			}
		}

//		if (logToFile)
//			bw.flush();
	}
 
Example 37
Project: r2rml-kit   File: R2RMLTarget.java   Source Code and License 5 votes vote down vote up
public void generateEntities(Resource class_, TableName tableName,
		TemplateValueMaker iriTemplate, List<Identifier> blankNodeColumns) {
	TermMap subjectMap = (iriTemplate == null)
			? createTermMap(toTemplate(tableName, blankNodeColumns), 
					TermType.BLANK_NODE) 
			: createTermMap(iriTemplate, null);
	if (class_ != null) {
		subjectMap.getClasses().add(ConstantIRI.create(class_));
	}
	addTriplesMap(tableName, createBaseTableOrView(tableName), subjectMap);
	if (iriTemplate != null) {
		iriTemplates.put(tableName, iriTemplate);
	}
}
 
Example 38
Project: c4a_data_repository   File: MappingGenerator.java   Source Code and License 5 votes vote down vote up
private void initVocabularyModel() {
	this.vocabModel.setNsPrefix("rdf", RDF.getURI());
	this.vocabModel.setNsPrefix("rdfs", RDFS.getURI());
	this.vocabModel.setNsPrefix("owl", OWL.getURI());
	this.vocabModel.setNsPrefix("dc", DC.getURI());
	this.vocabModel.setNsPrefix("xsd", XSDDatatype.XSD + "#");
	this.vocabModel.setNsPrefix("", this.vocabNamespaceURI);
	Resource r = ontologyResource();
	r.addProperty(RDF.type, OWL.Ontology);
	r.addProperty(OWL.imports, this.vocabModel.getResource(dropTrailingHash(DC.getURI())));
	r.addProperty(DC.creator, CREATOR);
}
 
Example 39
Project: c4a_data_repository   File: MappingGenerator.java   Source Code and License 5 votes vote down vote up
private void createVocabularyClass(RelationName tableName) {
	Resource r = classResource(tableName);
	r.addProperty(RDF.type, RDFS.Class);
	r.addProperty(RDF.type, OWL.Class);
	r.addProperty(RDFS.label, tableName.qualifiedName());
	r.addProperty(RDFS.isDefinedBy, ontologyResource());
}
 
Example 40
Project: c4a_data_repository   File: PageServlet.java   Source Code and License 5 votes vote down vote up
private Collection<Property> collectProperties(Model m, Resource r) {
	Collection<Property> result = new TreeSet<Property>();
	StmtIterator it = r.listProperties();
	while (it.hasNext()) {
		result.add(new Property(it.nextStatement(), false));
	}
	it = m.listStatements(null, null, r);
	while (it.hasNext()) {
		result.add(new Property(it.nextStatement(), true));
	}
	return result;
}