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

The following are top voted examples for showing how to use com.hp.hpl.jena.vocabulary.RDF. 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: r2rml-kit   File: JenaModelExample.java   Source Code and License 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 2
Project: r2rml-kit   File: VocabularySummarizer.java   Source Code and License 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 3
Project: r2rml-kit   File: D2RQCompilerTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testClassMapWithoutDuplicates() {
	sql.executeSQL("CREATE TABLE T (ID INT)");
	ClassMap cm1 = ClassMap.create(null, pattern1, mapping);
	// This asserts we have no duplicates. It's the default anyway for class maps. So we need no DISTINCT.
	cm1.setContainsDuplicates(false);
	PropertyBridge.create(null, RDF.type, cm1).setConstantValue(class1);
	// Check that we have no DISTINCT
	firstTripleRelation().getBaseTabular().accept(new OpVisitor.Default(true) {
		@Override
		public boolean visitEnter(DistinctOp table) {
			fail("There should be no Distinct(...) in " + table);
			return false;
		}
	});
	// Check that the asserted unique key is present
	assertFalse(firstTripleRelation().getBaseTabular().getUniqueKeys().isEmpty());
}
 
Example 4
Project: r2rml-kit   File: ConstantValueClassMapTest.java   Source Code and License 6 votes vote down vote up
public void setUp() {
	this.model = ModelFactory.createDefaultModel();
	this.mapping = new Mapping();
	this.database = new Database(this.model.createResource());
	this.mapping.addDatabase(this.database);
	
	concept = createClassMap("http://example.com/concept#@@[email protected]@");
	conceptTypeBridge = createPropertyBridge(concept, RDF.type.getURI());
	conceptTypeBridge.setConstantValue(model.createResource("http://www.w3.org/2004/02/skos/core#Concept"));
	
	collection = createConstantClassMap("http://example.com/collection#MyConceptCollection");
	collectionTypeBridge = createPropertyBridge(collection, RDF.type.getURI());
	collectionTypeBridge.setConstantValue(model.createResource("http://www.w3.org/2004/02/skos/core#Collection"));

	memberBridge = createPropertyBridge(collection, "http://www.w3.org/2004/02/skos/core#member");
	memberBridge.setRefersToClassMap(concept);
	memberBridge.addCondition("c.foo = 1");
}
 
Example 5
Project: r2rml-kit   File: PrettyPrinterTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testNodePrettyPrinting() {
	assertEquals("\"foo\"", 
			PrettyPrinter.toString(Node.createLiteral("foo")));
	assertEquals("\"foo\"@en", 
			PrettyPrinter.toString(Node.createLiteral("foo", "en", null)));
	assertEquals("\"1\"^^xsd:int",
			PrettyPrinter.toString(Node.createLiteral("1", null, XSDDatatype.XSDint)));
	assertEquals("\"1\"^^xsd:int",
			PrettyPrinter.toString(Node.createLiteral("1", null, XSDDatatype.XSDint), PrefixMapping.Standard));
	assertEquals("_:foo", 
			PrettyPrinter.toString(Node.createAnon(new AnonId("foo"))));
	assertEquals("<http://example.org/>", 
			PrettyPrinter.toString(Node.createURI("http://example.org/")));
	assertEquals("<" + RDF.type.getURI() + ">", 
			PrettyPrinter.toString(RDF.type.asNode(), new PrefixMappingImpl()));
	assertEquals("rdf:type", 
			PrettyPrinter.toString(RDF.type.asNode(), PrefixMapping.Standard));
	assertEquals("?x", 
			PrettyPrinter.toString(Node.createVariable("x")));
	assertEquals("?ANY",
			PrettyPrinter.toString(Node.ANY));
}
 
Example 6
Project: c4a_data_repository   File: JenaModelExample.java   Source Code and License 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 7
Project: c4a_data_repository   File: CompileTest.java   Source Code and License 6 votes vote down vote up
public void setUp() {
	this.model = ModelFactory.createDefaultModel();
	this.mapping = new Mapping();
	this.database = new Database(this.model.createResource());
	database.useConnectedDB(new DummyDB());
	this.mapping.addDatabase(this.database);

	employees = createClassMap("http://test/[email protected]@[email protected]@");
	employees.addAlias("employees AS e");
	employees.addJoin("e.ID = foo.bar");
	employees.addCondition("e.status = 'active'");
	managerBridge = createPropertyBridge(employees, "http://terms.example.org/manager");
	managerBridge.addAlias("e AS m");
	managerBridge.setRefersToClassMap(this.employees);
	managerBridge.addJoin("e.manager = m.ID");
	
	cities = createClassMap("http://test/[email protected]@[email protected]@");
	citiesTypeBridge = createPropertyBridge(cities, RDF.type.getURI());
	citiesTypeBridge.setConstantValue(model.createResource("http://terms.example.org/City"));
	citiesNameBridge = createPropertyBridge(cities, "http://terms.example.org/name");
	citiesNameBridge.setColumn("c.name");
	countries = createClassMap("http://test/countries/@@[email protected]@");
	countries.setContainsDuplicates(true);
	countriesTypeBridge = createPropertyBridge(countries, RDF.type.getURI());
	countriesTypeBridge.setConstantValue(model.createResource("http://terms.example.org/Country"));
}
 
Example 8
Project: c4a_data_repository   File: ConstantValueClassMapTest.java   Source Code and License 6 votes vote down vote up
public void setUp() {
	this.model = ModelFactory.createDefaultModel();
	this.mapping = new Mapping();
	this.database = new Database(this.model.createResource());
	this.mapping.addDatabase(this.database);
	
	concept = createClassMap("http://example.com/concept#@@[email protected]@");
	conceptTypeBridge = createPropertyBridge(concept, RDF.type.getURI());
	conceptTypeBridge.setConstantValue(model.createResource("http://www.w3.org/2004/02/skos/core#Concept"));
	
	collection = createConstantClassMap("http://example.com/collection#MyConceptCollection");
	collectionTypeBridge = createPropertyBridge(collection, RDF.type.getURI());
	collectionTypeBridge.setConstantValue(model.createResource("http://www.w3.org/2004/02/skos/core#Collection"));

	memberBridge = createPropertyBridge(collection, "http://www.w3.org/2004/02/skos/core#member");
	memberBridge.setRefersToClassMap(concept);
	memberBridge.addCondition("c.foo = 1");
}
 
Example 9
Project: c4a_data_repository   File: PrettyPrinterTest.java   Source Code and License 6 votes vote down vote up
public void testNodePrettyPrinting() {
	assertEquals("\"foo\"", 
			PrettyPrinter.toString(Node.createLiteral("foo")));
	assertEquals("\"foo\"@en", 
			PrettyPrinter.toString(Node.createLiteral("foo", "en", null)));
	assertEquals("\"1\"^^<" + XSDDatatype.XSDint.getURI() + ">",
			PrettyPrinter.toString(Node.createLiteral("1", null, XSDDatatype.XSDint)));
	assertEquals("\"1\"^^xsd:int",
			PrettyPrinter.toString(Node.createLiteral("1", null, XSDDatatype.XSDint), PrefixMapping.Standard));
	assertEquals("_:foo", 
			PrettyPrinter.toString(Node.createAnon(new AnonId("foo"))));
	assertEquals("<http://example.org/>", 
			PrettyPrinter.toString(Node.createURI("http://example.org/")));
	assertEquals("<" + RDF.type.getURI() + ">", 
			PrettyPrinter.toString(RDF.type.asNode(), new PrefixMappingImpl()));
	assertEquals("rdf:type", 
			PrettyPrinter.toString(RDF.type.asNode(), PrefixMapping.Standard));
	assertEquals("?x", 
			PrettyPrinter.toString(Node.createVariable("x")));
	assertEquals("?ANY",
			PrettyPrinter.toString(Node.ANY));
}
 
Example 10
Project: BimSPARQL   File: HasLowerStoreyPF.java   Source Code and License 6 votes vote down vote up
@Override
protected HashSet<Node> getRelatedSubjects(Node node, ExecutionContext execCxt) {
	HashSet<Node> results = new HashSet<Node>();

	Graph graph = execCxt.getActiveGraph();

	Node clazz = NodeFactory.createURI(Namespace.IFC2X3_TC1 + "IfcBuildingStorey");
	LinkedList<Storey> storeys = new LinkedList<Storey>();
	if (graph.contains(node, RDF.type.asNode(), clazz)) {
		Storey storey = new Storey(node, elevation(node, graph));
		ExtendedIterator<Triple> triples = graph.find(null, RDF.type.asNode(), clazz);
		while (triples.hasNext()) {
			Node subject = triples.next().getSubject();
			Storey s = new Storey(subject, elevation(subject, graph));
			if (s.elevation > storey.elevation) {
				addStorey(storeys, s, graph);
			}
		}
		if (storeys.size() > 0) {
			results.add(storeys.get(0).storey);
		}
	}
	return results;
}
 
Example 11
Project: BimSPARQL   File: HasLowerStoreyPF.java   Source Code and License 6 votes vote down vote up
@Override
protected HashSet<Node> getRelatedObjects(Node node, ExecutionContext execCxt) {
	HashSet<Node> results = new HashSet<Node>();

	Graph graph = execCxt.getActiveGraph();

	Node clazz = NodeFactory.createURI(Namespace.IFC2X3_TC1 + "IfcBuildingStorey");
	LinkedList<Storey> storeys = new LinkedList<Storey>();
	if (graph.contains(node, RDF.type.asNode(), clazz)) {
		Storey storey = new Storey(node, elevation(node, graph));
		ExtendedIterator<Triple> triples = graph.find(null, RDF.type.asNode(), clazz);
		while (triples.hasNext()) {
			Node subject = triples.next().getSubject();
			Storey s = new Storey(subject, elevation(subject, graph));
			if (s.elevation < storey.elevation) {
				addStorey(storeys, s, graph);
			}
		}
		if (storeys.size() > 0) {
			results.add(storeys.get(storeys.size() - 1).storey);
		}
	}
	return results;

}
 
Example 12
Project: Ifc2Rdf   File: Ifc2RdfModelExporter.java   Source Code and License 6 votes vote down vote up
public Resource convertEntityToResource(IfcEntityBase value) {
	if (value instanceof IfcEntity) {
		IfcEntity entity = (IfcEntity)value;
		if (entity.hasName()) {
			return super.createUriResource(super.formatModelName(entity.getName()));
		} else {
			return super.createAnonResource(String.format(Ifc2RdfVocabulary.IFC.BLANK_NODE_ENTITY_URI_FORMAT, entity.getLineNumber()));
		}
	} else { // entityBase instanceof IfcShortEntity
		Resource resource = super.createAnonResource();
		resource.addProperty(RDF.type, createUriResource(super.formatTypeName(value.getTypeInfo())));
		IfcLiteralValue literalValue = ((IfcShortEntity)value).getValue();
		resource.addProperty(RDF.value, convertLiteralToNode(literalValue));
		return resource;
	}
}
 
Example 13
Project: Ifc2Rdf   File: Ifc2RdfSchemaExporter.java   Source Code and License 6 votes vote down vote up
private void exportSelectTypeInfo(IfcSelectTypeInfo typeInfo) {

		Resource typeResource = super.createUriResource(super.formatTypeName(typeInfo)); 
		adapter.exportTriple(typeResource, RDF.type, OWL.Class);

		List<String> subTypeNames = typeInfo.getSelectTypeInfoNames();
		List<Resource> nodes = new ArrayList<>();
		for (String typeName : subTypeNames) {
			nodes.add(super.createUriResource(super.formatOntologyName(typeName)));
		}			
		RDFList rdfList = super.createList(nodes);			

		// See samples: [2, p.250]
		adapter.exportTriple(typeResource, OWL.unionOf, rdfList);
		
//		See samples: [2, pp.135-136]
//		for (String subTypeName : subTypeNames) {
//			writeSentence(generateName(subTypeName), RDFS.subClassOf, typeName);
//		}

	}
 
Example 14
Project: CSV2LOD   File: CSV2RDF.java   Source Code and License 6 votes vote down vote up
public void CreatePersonModel()
{
    Model pm = ModelFactory.createDefaultModel();
    pm.setNsPrefix("RDF", RDF.getURI());
    pm.setNsPrefix("foaf", FOAF.getURI());
    pm.setNsPrefix("DC", DCTerms.getURI());
    
    ArrayList<String> persons = new ArrayList<String>();
    persons.add("Kumar");
    persons.add("Arjun");
    
    int i = 1;
    for(String p : persons)
    {
        Resource p1 = pm.createResource("http://www.testsite.com/persons/p"+i);
        p1.addProperty(FOAF.firstName, p);
        p1.addProperty(DCTerms.description, "Description of person "+i);
        p1.addProperty(FOAF.mbox, p+i+"[email protected]");
        
        i++;
    }
    
    this.writeModelToFile(pm, "RDF/XML", "personData");
}
 
Example 15
Project: Ifc2Rdf   File: Ifc2RdfModelExporter.java   Source Code and License 6 votes vote down vote up
public Resource convertEntityToResource(IfcEntityBase value) {
	if (value instanceof IfcEntity) {
		IfcEntity entity = (IfcEntity)value;
		if (entity.hasName()) {
			return super.createUriResource(super.formatModelName(entity.getName()));
		} else {
			return super.createAnonResource(String.format(Ifc2RdfVocabulary.IFC.BLANK_NODE_ENTITY_URI_FORMAT, entity.getLineNumber()));
		}
	} else { // entityBase instanceof IfcShortEntity
		Resource resource = super.createAnonResource();
		resource.addProperty(RDF.type, createUriResource(super.formatTypeName(value.getTypeInfo())));
		IfcLiteralValue literalValue = ((IfcShortEntity)value).getValue();
		resource.addProperty(RDF.value, convertLiteralToNode(literalValue));
		return resource;
	}
}
 
Example 16
Project: Ifc2Rdf   File: Ifc2RdfSchemaExporter.java   Source Code and License 6 votes vote down vote up
private void exportSelectTypeInfo(IfcSelectTypeInfo typeInfo) {

		Resource typeResource = super.createUriResource(super.formatTypeName(typeInfo)); 
		adapter.exportTriple(typeResource, RDF.type, OWL.Class);

		List<String> subTypeNames = typeInfo.getSelectTypeInfoNames();
		List<Resource> nodes = new ArrayList<>();
		for (String typeName : subTypeNames) {
			nodes.add(super.createUriResource(super.formatOntologyName(typeName)));
		}			
		RDFList rdfList = super.createList(nodes);			

		// See samples: [2, p.250]
		adapter.exportTriple(typeResource, OWL.unionOf, rdfList);
		
//		See samples: [2, pp.135-136]
//		for (String subTypeName : subTypeNames) {
//			writeSentence(generateName(subTypeName), RDFS.subClassOf, typeName);
//		}

	}
 
Example 17
Project: Ifc2Rdf   File: Ifc2RdfSchemaExporter.java   Source Code and License 6 votes vote down vote up
private void exportEnumerationTypeInfo(IfcEnumerationTypeInfo typeInfo) {
	
	String typeUri = super.formatTypeName(typeInfo);
	Resource typeResource = createUriResource(typeUri);
	adapter.exportTriple(typeResource, RDF.type, OWL.Class);
	adapter.exportTriple(typeResource, RDFS.subClassOf, Ifc2RdfVocabulary.EXPRESS.Enum);		

	List<String> enumValues = typeInfo.getValues(); 
	List<RDFNode> enumValueNodes = new ArrayList<>();

	for (String value : enumValues) {
		enumValueNodes.add(super.createUriResource(super.formatOntologyName(value)));
	}		
	
	if (owlProfileList.supportsRdfProperty(OWL.oneOf, EnumSet.of(RdfTripleObjectTypeEnum.ZeroOrOneOrMany))) {			
		Resource equivalentTypeResource = super.createAnonResource();
		adapter.exportTriple(typeResource, OWL.equivalentClass, equivalentTypeResource);

		RDFList rdfList = super.createList(enumValueNodes);			
		adapter.exportTriple(equivalentTypeResource, OWL.oneOf, rdfList);
	} else { // if (!context.isEnabledOption(Ifc2RdfConversionOptionsEnum.ForceConvertEnumerationValuesToString)) {
		enumValueNodes.stream().forEach(node ->
				adapter.exportTriple((Resource)node, RDF.type, typeResource));			
	}	
	
}
 
Example 18
Project: OpenCollegeGraph   File: PrettyPrinterTest.java   Source Code and License 6 votes vote down vote up
public void testNodePrettyPrinting() {
	assertEquals("\"foo\"", 
			PrettyPrinter.toString(Node.createLiteral("foo")));
	assertEquals("\"foo\"@en", 
			PrettyPrinter.toString(Node.createLiteral("foo", "en", null)));
	assertEquals("\"1\"^^<" + XSDDatatype.XSDint.getURI() + ">",
			PrettyPrinter.toString(Node.createLiteral("1", null, XSDDatatype.XSDint)));
	assertEquals("\"1\"^^xsd:int",
			PrettyPrinter.toString(Node.createLiteral("1", null, XSDDatatype.XSDint), PrefixMapping.Standard));
	assertEquals("_:foo", 
			PrettyPrinter.toString(Node.createAnon(new AnonId("foo"))));
	assertEquals("<http://example.org/>", 
			PrettyPrinter.toString(Node.createURI("http://example.org/")));
	assertEquals("<" + RDF.type.getURI() + ">", 
			PrettyPrinter.toString(RDF.type.asNode(), new PrefixMappingImpl()));
	assertEquals("rdf:type", 
			PrettyPrinter.toString(RDF.type.asNode(), PrefixMapping.Standard));
	assertEquals("?x", 
			PrettyPrinter.toString(Node.createVariable("x")));
	assertEquals("?ANY",
			PrettyPrinter.toString(Node.ANY));
}
 
Example 19
Project: bygle-ldp   File: LDPService.java   Source Code and License 6 votes vote down vote up
private Content readContent(Model modelTpl, String hostAbout, String about, String inputFormat, String outputFormat, boolean isImport) throws UnsupportedEncodingException, ConfigurationException, URISyntaxException {
	Iterator<Statement> iterator = modelTpl.getResource(hostAbout).listProperties(RDF.type);
	Content result = null;
	while (iterator.hasNext()) {
		Resource resourceType = iterator.next().getResource();
		if (resourceType.toString().equalsIgnoreCase(LDPVoc.Container.stringValue())) {
			result = new Content(about, BygleSystemUtils.RESOURCE_TYPE_RDF_CONTAINER, resourceType, modelTpl, inputFormat, outputFormat != null ? outputFormat : BygleSystemUtils.defaultOutputFormat);
			break;
		} else if (resourceType.toString().equalsIgnoreCase(LDPVoc.BasicContainer.stringValue())) {
			result = new Content(about, BygleSystemUtils.RESOURCE_TYPE_RDF_BASIC_CONTAINER, resourceType, modelTpl, inputFormat, outputFormat != null ? outputFormat : BygleSystemUtils.defaultOutputFormat);
			break;
		} else if (resourceType.toString().equalsIgnoreCase(LDPVoc.DirectContainer.stringValue())) {
			result = new Content(about, BygleSystemUtils.RESOURCE_TYPE_RDF_DIRECT_CONTAINER, resourceType, modelTpl, inputFormat, outputFormat != null ? outputFormat : BygleSystemUtils.defaultOutputFormat);
			break;
		} else if (resourceType.toString().equalsIgnoreCase(LDPVoc.IndirectContainer.stringValue())) {
			result = new Content(about, BygleSystemUtils.RESOURCE_TYPE_RDF_INDIRECT_CONTAINER, resourceType, modelTpl, inputFormat, outputFormat != null ? outputFormat : BygleSystemUtils.defaultOutputFormat);
			break;
		} else if (resourceType.toString().equalsIgnoreCase(LDPVoc.RDFSource.stringValue())) {
			result = new Content(about, BygleSystemUtils.RESOURCE_TYPE_RDF_RESOURCE, resourceType, modelTpl, inputFormat, outputFormat != null ? outputFormat : BygleSystemUtils.defaultOutputFormat);
		} else if (isImport) {
			result = new Content(about, BygleSystemUtils.RESOURCE_TYPE_RDF_RESOURCE, resourceType, modelTpl, inputFormat, outputFormat != null ? outputFormat : BygleSystemUtils.defaultOutputFormat);
		}
	}
	return result;
}
 
Example 20
Project: GPML2RDF   File: AnchorConverter.java   Source Code and License 6 votes vote down vote up
/**
 * conversion only GPML vocabulary
 */
public static void parseAnchorGpml(MAnchor anchor, Model model, Resource lineRes, DataHandlerGpml data) {
	Resource anchorRes = model.createResource(lineRes.getURI() + "/Anchor/" + anchor.getGraphId());

	anchorRes.addProperty(RDF.type, Gpml.ANCHOR);
	anchorRes.addProperty(DCTerms.isPartOf, lineRes);
	anchorRes.addProperty(DCTerms.isPartOf, data.getPathwayRes());
	
	lineRes.addProperty(Gpml.HAS_ANCHOR, anchorRes);
	
	anchorRes.addLiteral(Gpml.GRAPH_ID, anchor.getGraphId());
	anchorRes.addLiteral(Gpml.POSITION, anchor.getPosition());
	anchorRes.addLiteral(Gpml.SHAPE, anchor.getShape().getName());
	
	data.getAnchors().put(anchor, anchorRes);
}
 
Example 21
Project: GPML2RDF   File: PublicationXrefConverter.java   Source Code and License 6 votes vote down vote up
/**
 * conversion only GPML vocabulary
 */
public static void parsePublicationXrefGpml(PublicationXref xref, Resource parent, Model model, DataHandlerGpml data) {
	Resource pubXrefRes = null;
	if (xref.getPubmedId() != null && xref.getPubmedId().trim().length() != 0) {
		pubXrefRes = model.createResource(Utils.IDENTIFIERS_ORG_URL + "/pubmed/" + xref.getPubmedId().trim());
	} else {
		pubXrefRes = model.createResource(data.getPathwayRes().getURI() + "/pub/" + xref.getId().trim());
	}
	pubXrefRes.addProperty(RDF.type, Gpml.PUBLICATION_XREF);
	pubXrefRes.addLiteral(Gpml.ID, xref.getPubmedId() != null ? xref.getPubmedId() : "");
	pubXrefRes.addLiteral(Gpml.DATABASE, "Pubmed");
	
	pubXrefRes.addProperty(DCTerms.isPartOf, parent);			
	parent.addProperty(Gpml.HAS_PUBLICATION_XREF, pubXrefRes);
	
	data.getPubXrefs().put(xref, pubXrefRes);
}
 
Example 22
Project: GPML2RDF   File: InfoBoxConverter.java   Source Code and License 6 votes vote down vote up
/**
 * conversion only GPML vocabulary
 */
public static void parseInfoBoxGpml(PathwayElement e, Model model, DataHandlerGpml data) {
	String graphId = e.getGraphId();
	if(e.getGraphId() == null) {
		graphId = data.getPathway().getUniqueGraphId();
	}
	Resource infoboxRes = model.createResource(data.getPathwayRes().getURI() + "/InfoBox/" + graphId);

	infoboxRes.addProperty(RDF.type, Gpml.INFO_BOX);
	infoboxRes.addProperty(DCTerms.isPartOf, data.getPathwayRes());		
	data.getPathwayRes().addProperty(Gpml.HAS_INFO_BOX, infoboxRes);
	
	infoboxRes.addLiteral(Gpml.CENTER_X, e.getMCenterX());
	infoboxRes.addLiteral(Gpml.CENTER_Y, e.getMCenterY());
	
	data.getPathwayElements().put(e, infoboxRes);
}
 
Example 23
Project: OpenCollegeGraph   File: ConstantValueClassMapTest.java   Source Code and License 6 votes vote down vote up
public void setUp() {
	this.model = ModelFactory.createDefaultModel();
	this.mapping = new Mapping();
	this.database = new Database(this.model.createResource());
	this.mapping.addDatabase(this.database);
	
	concept = createClassMap("http://example.com/concept#@@[email protected]@");
	conceptTypeBridge = createPropertyBridge(concept, RDF.type.getURI());
	conceptTypeBridge.setConstantValue(model.createResource("http://www.w3.org/2004/02/skos/core#Concept"));
	
	collection = createConstantClassMap("http://example.com/collection#MyConceptCollection");
	collectionTypeBridge = createPropertyBridge(collection, RDF.type.getURI());
	collectionTypeBridge.setConstantValue(model.createResource("http://www.w3.org/2004/02/skos/core#Collection"));

	memberBridge = createPropertyBridge(collection, "http://www.w3.org/2004/02/skos/core#member");
	memberBridge.setRefersToClassMap(concept);
	memberBridge.addCondition("c.foo = 1");
}
 
Example 24
Project: GPML2RDF   File: Utils.java   Source Code and License 6 votes vote down vote up
public static void setModelPrefix(Model model){
	model.setNsPrefix("biopax", Biopax_level3.getURI());
	model.setNsPrefix("gpml", Gpml.getURI());
	model.setNsPrefix("wp", Wp.getURI());
	model.setNsPrefix("xsd", XSD.getURI());
	model.setNsPrefix("rdf", RDF.getURI());
	model.setNsPrefix("rdfs", RDFS.getURI());
	model.setNsPrefix("dcterms", DCTerms.getURI());
	model.setNsPrefix("wprdf", "http://rdf.wikipathways.org/");
	model.setNsPrefix("foaf", FOAF.getURI());
	model.setNsPrefix("dc", DC.getURI());
	model.setNsPrefix("skos", Skos.getURI());
	model.setNsPrefix("void", Void.getURI());
	model.setNsPrefix("wprdf", "http://rdf.wikipathways.org/");
	model.setNsPrefix("pav", Pav.getURI());
	model.setNsPrefix("prov", Prov.getURI());
	model.setNsPrefix("dcterms", DCTerms.getURI());
	model.setNsPrefix("freq", Freq.getURI());
}
 
Example 25
Project: mindraider   File: OutlineCustodian.java   Source Code and License 6 votes vote down vote up
public ResourceDescriptor[] getAllNoteDescriptors(String outlineUri) {
    Model outlineModel;
    try {
        outlineModel = MindRaider.outlineCustodian.getModel(outlineUri);
        Property property = RDF.type;
        String literal = MindRaiderConstants.MR_OWL_CLASS_CONCEPT;
        StmtIterator i = outlineModel.listStatements((com.hp.hpl.jena.rdf.model.Resource)null,property,outlineModel.getResource(literal));
        ArrayList<String> noteUris=new ArrayList<String>();
        while(i.hasNext()) {
            Statement s=i.nextStatement();
            noteUris.add(s.getSubject().getURI());
        }
        return getDescriptorsForNoteUris(true, outlineModel, noteUris.toArray(new String[noteUris.size()]));
    } catch (Exception e) {
        logger.debug("Unable to get resource descriptors",e); // {{debug}}
    }

    return null;
}
 
Example 26
Project: mindraider   File: LabelCustodian.java   Source Code and License 6 votes vote down vote up
/**
 * Add folder to the model.
 *
 * @param mindMapSequence
 *            the mind map sequence.
 * @param folderType
 *            the folder type.
 * @param fResource
 *            the resource.
 * @param folderResourcePath
 *            the folder resource path String
 * @return the resource
 */
private com.hp.hpl.jena.rdf.model.Resource addFolderToModel(
        Seq mindMapSequence,
        com.hp.hpl.jena.rdf.model.Resource folderType, 
        Resource fResource, 
        String folderResourcePath) {
    
    com.hp.hpl.jena.rdf.model.Resource folderRdfResource;
    folderRdfResource 
        = (com.hp.hpl.jena.rdf.model.Resource) labelsModel.newResource(fResource.getMetadata().getUri().toString(), false);
    // rdf:type - it's sequence
    folderRdfResource.addProperty(RDF.type, RDF.Seq);
    // rdf:type - it's folder
    folderRdfResource.addProperty(RDF.type, folderType);
    // xlink:href - specify relative location (along with profile's
    // repository home it allows to construct full path
    folderRdfResource.addProperty(MindRaiderVocabulary.xlinkHref, MindRaider.profile.getRelativePath(folderResourcePath));
    // rdfs:label
    folderRdfResource.addProperty(RDFS.label, new FolderResource(fResource).getLabel());
    // add folder to the parent sequence
    mindMapSequence.add(folderRdfResource);
    return folderRdfResource;
}
 
Example 27
Project: mindraider   File: Installer.java   Source Code and License 6 votes vote down vote up
/**
 * upgrade to 0.507 version of MR.
 */
private static void upgradeTo0507() {
    logger.debug(Messages.getString("Installer.upgradingTo", "0.507"));

    // update type of the resource in the profile
    Resource resource = MindRaider.profile.getModel().getResource(
            MindRaiderConstants.MR_RDF_NS + MindRaider.profile.getProfileName());
    resource.removeAll(RDF.type);
    resource.addProperty(RDF.type, MindRaider.profile.getModel().createResource(
            MindRaiderConstants.MR_OWL_CLASS_PROFILE));

    // update version in the profile
    MindRaider.profile.setVersion(MindRaider.getVersion());
    MindRaider.profile.save();

    // @todo there is profile issue - user QName is not unique :-Z (taken
    // from MR namespace)
}
 
Example 28
Project: mindraider   File: BriefFacet.java   Source Code and License 6 votes vote down vote up
public boolean showThisStatement(Statement statement) {
    Property predicate = statement.getPredicate();
    if (predicate.equals(RDF.type) || predicate.equals(DC.date) || predicate.equals(RDFS.label)
            || predicate.equals(RDFS.comment) || predicate.equals(MindRaiderVocabulary.isDiscarded)
            || predicate.equals(MindRaiderVocabulary.xlinkHref)
            || predicate.equals(MindRaiderVocabulary.flagProperty)) {
        return false;
    }

    // do not show trash content
    String uri = statement.getSubject().getURI();
    if (uri != null && uri.endsWith(NoteCustodian.NOTEBOOK_TRASH_LOCAL_NAME)) {
        return false;
    }

    return true;
}
 
Example 29
Project: Tapioca   File: DumpFileAnalyzer.java   Source Code and License 6 votes vote down vote up
protected Model generateVoidModel(String datsetUri, VoidExtractor extractor, SpecialClassExtractor sExtractor) {
    Model voidModel = ModelFactory.createDefaultModel();
    Resource datasetResource = voidModel.createResource(datsetUri);

    voidModel.add(datasetResource, RDF.type, VOID.Dataset);

    long entities;
    entities = addCountedUris(extractor.getCountedClasses(), voidModel, datasetResource, VOID.classPartition,
            VOID.clazz, VOID.entities);
    addCountedUris(sExtractor.getCountedSpecialClasses(), voidModel, datasetResource, EVOID.classPartition,
            EVOID.specialClass, EVOID.entities);
    voidModel.addLiteral(datasetResource, VOID.classes,
            extractor.getCountedClasses().assigned + sExtractor.getCountedSpecialClasses().assigned);
    voidModel.addLiteral(datasetResource, VOID.entities, entities);

    long triples = addCountedUris(extractor.getCountedProperties(), voidModel, datasetResource,
            VOID.propertyPartition, VOID.property, VOID.triples);
    voidModel.addLiteral(datasetResource, VOID.properties, extractor.getCountedProperties().assigned);
    voidModel.addLiteral(datasetResource, VOID.triples, triples);
    if ((entities == 0) && (triples == 0)) {
        LOGGER.error("Got an empty VOID model without an entity and a triple. Returning null.");
        return null;
    }
    return voidModel;
}
 
Example 30
Project: statistics2cubes   File: Table2CubeConverter.java   Source Code and License 6 votes vote down vote up
private Resource createDataset() {
    Resource ds = model.createResource(localNS.DATASET + "-" + id);
    ds.addProperty(RDF.type, QB.DATASET);
    ds.addProperty(RDFS.label, table.getMetadata().getLabel());
    ds.addProperty(RDFS.comment, table.getMetadata().getDescription());
    ds.addProperty(DC.relation, RELATION);

    if (Config.GENERATE_1_2) {
        ds.addProperty(DC.format, VERSION_1_2);
    } else {
        ds.addProperty(DC.format, VERSION_1_1);
    }

    for (String source : table.getMetadata().getSources()) {
        ds.addProperty(DC.source, source);
    }

    Literal l = model.createTypedLiteral(GregorianCalendar.getInstance());
    ds.addProperty(DC.date, l);

    return ds;
}
 
Example 31
Project: statistics2cubes   File: Table2CubeConverter.java   Source Code and License 6 votes vote down vote up
private void createObservations(List<Property> headers, Resource ds) {
    HashMap<Integer, HashMap<String, Resource>> entities = createEntities();
    String obsPrefix = localNS.DATASET + "-" + id + "/" + localNS.OBS_NAME + "-";

    for (Row row : table.getRows()) {
        Resource obs = model.createResource(obsPrefix + UUID.randomUUID()).addProperty(RDF.type, QB.OBSERVATION);
        obs.addProperty(QB.DATASET_PROPERTY, ds);

        for (int i = 0; i < row.getCells().size(); i++) {
            Cell cell = row.getCells().get(i);

            if (i < getMeasureCount()) {
                // TODO use more data types
                XSDDatatype xsdDatatype = XSDDatatype.XSDdouble;
                Literal literal = model.createTypedLiteral(cell.getValue().getValue(), xsdDatatype);
                obs.addProperty(headers.get(i), literal);
            } else {
                Resource entity = entities.get(i).get(cell.getValue().getValue());
                obs.addProperty(headers.get(i), entity);
            }
        }
    }
}
 
Example 32
Project: statistics2cubes   File: Converter.java   Source Code and License 6 votes vote down vote up
private Resource createDataset() {
    Resource ds = model.createResource(localNS.DATASET + "-" + id);
    ds.addProperty(RDF.type, QB.DATASET);
    ds.addProperty(RDFS.label, table.getMetadata().getLabel());
    ds.addProperty(RDFS.comment, table.getMetadata().getDescription());
    ds.addProperty(DC.relation, RELATION);

    if (version.equals("1.1")) {
        ds.addProperty(DC.format, VERSION_1_1);
    } else {
        ds.addProperty(DC.format, VERSION_1_2);
    }

    for (String source : table.getMetadata().getSources()) {
        ds.addProperty(DC.source, source);
    }

    Literal l = model.createTypedLiteral(GregorianCalendar.getInstance());
    ds.addProperty(DC.date, l);

    return ds;
}
 
Example 33
Project: statistics2cubes   File: Converter.java   Source Code and License 6 votes vote down vote up
private void createObservations(List<Property> headers, Resource ds) {
    HashMap<Integer, HashMap<String, Resource>> entities = createEntities();
    String obsPrefix = localNS.DATASET + "-" + id + "/" + localNS.OBS_NAME + "-";

    for (Row row : table.getRows()) {
        Resource obs = model.createResource(obsPrefix + UUID.randomUUID()).addProperty(RDF.type, QB.OBSERVATION);
        obs.addProperty(QB.DATASET_PROPERTY, ds);

        for (int i = 0; i < row.getCells().size(); i++) {
            Cell cell = row.getCells().get(i);

            if (i < getMeasureCount()) {
                // TODO use more data types
                XSDDatatype xsdDatatype = XSDDatatype.XSDdouble;
                Literal literal = model.createTypedLiteral(cell.getValue().getValue(), xsdDatatype);
                obs.addProperty(headers.get(i), literal);
            } else {
                Resource entity = entities.get(i).get(cell.getValue().getValue());
                obs.addProperty(headers.get(i), entity);
            }
        }
    }
}
 
Example 34
Project: OpenCollegeGraph   File: JenaModelExample.java   Source Code and License 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 35
Project: harvesters   File: SubprojectsSellersImpl.java   Source Code and License 5 votes vote down vote up
public static void subprojectsSellers() {

        //services for each table
        ApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml");
        SubProjectSellersService sub = (SubProjectSellersService) ctx.getBean("subProjectSellersServiceImpl");

        List<SubProjectSellers> subProjectSeller = sub.getSubProjectSellers();

        //--------------RDF Model--------------//
        Model model = ModelFactory.createDefaultModel();
        Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
        InfModel infModel = ModelFactory.createInfModel(reasoner, model);

        model.setNsPrefix("elod", OntologySpecification.elodPrefix);
        model.setNsPrefix("gr", OntologySpecification.goodRelationsPrefix);


        for (SubProjectSellers subProjectSeller1 : subProjectSeller) {
            Resource instanceSeller = infModel.createResource(OntologySpecification.instancePrefix
                    + "Organization/" + subProjectSeller1.getSellerId());
            Resource instanceSubProject = infModel.createResource(OntologySpecification.instancePrefix
                    + "Subproject/" + subProjectSeller1.getOps() + "/" + subProjectSeller1.getSubProjectId());
            infModel.add(instanceSeller, RDF.type, OntologySpecification.organizationResource);
            infModel.add(instanceSeller, RDF.type, OntologySpecification.businessResource);
            infModel.add(instanceSubProject, RDF.type, OntologySpecification.subProjectResource);
            instanceSubProject.addProperty(OntologySpecification.seller, instanceSeller);
        }

        try {
            FileOutputStream fout = new FileOutputStream(
                    "/Users/giovaf/Documents/yds_pilot1/espa_tests/22-02-2016_ouput/subProjectSellersEspa.rdf");
            model.write(fout);
        } catch (IOException e) {
            System.out.println("Exception caught" + e.getMessage());
        }
    }
 
Example 36
Project: harvesters   File: SellersImpl.java   Source Code and License 5 votes vote down vote up
public static void espaSellers() {

        ApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml");
        SellersService sellers = (SellersService) ctx.getBean("sellersServiceImpl");

        List<Sellers> seller = sellers.getSellers();

        //--------------RDF Model--------------//
        Model model = ModelFactory.createDefaultModel();
        Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
        InfModel infModel = ModelFactory.createInfModel(reasoner, model);

        model.setNsPrefix("elod", OntologySpecification.elodPrefix);
        model.setNsPrefix("gr", OntologySpecification.goodRelationsPrefix);
        model.setNsPrefix("vcard", OntologySpecification.vcardPrefix);

        for (Sellers seller1 : seller) {
            Resource instanceSeller = infModel.createResource(OntologySpecification.instancePrefix + "Organization/" + seller1.getId());
            infModel.add(instanceSeller, RDF.type, OntologySpecification.organizationResource);
            instanceSeller.addProperty(OntologySpecification.name, seller1.getEponimia(), XSDDatatype.XSDstring);
        }

        try {
            FileOutputStream fout = new FileOutputStream(
                    "/Users/giovaf/Documents/yds_pilot1/espa_tests/22-02-2016_ouput/sellersEspa.rdf");
            model.write(fout);
        } catch (IOException e) {
            System.out.println("Exception caught" + e.getMessage());
        }
    }
 
Example 37
Project: ld-sniffer   File: Evaluation.java   Source Code and License 5 votes vote down vote up
public void addEvaluationActivity(Model model, Date startTime, Date endTime) {

        evaluation.addProperty(RDF.type, EVAL.Evaluation);
        evaluation.addProperty(RDF.type, PROV.Activity);
        evaluation.addLiteral(EVAL.performedOn, ResourceFactory.createTypedLiteral( DATE_FORMAT.format(startTime), XSDDatatype.XSDdateTime));
        evaluation.addLiteral(PROV.startedAtTime, ResourceFactory.createTypedLiteral( DATE_FORMAT.format(startTime), XSDDatatype.XSDdateTime));
        evaluation.addLiteral(PROV.endedAtTime, ResourceFactory.createTypedLiteral( DATE_FORMAT.format(endTime), XSDDatatype.XSDdateTime));
        evaluation.addProperty(EVAL.evaluatedSubject, subject);
        evaluation.addProperty(LDQ.utilizes, LDQM.AT_SPARQL_Query);
        evaluation.addProperty(LDQ.utilizes, LDQM.AT_Url_Dereferencing);
    }
 
Example 38
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 39
Project: r2rml-kit   File: VocabularySummarizer.java   Source Code and License 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 40
Project: r2rml-kit   File: VocabularySummarizer.java   Source Code and License 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;
}
 
Example 41
Project: r2rml-kit   File: VocabularySummarizer.java   Source Code and License 5 votes vote down vote up
public Model triplesInvolvingVocabulary(Model model) {
	Model result = ModelFactory.createDefaultModel();
	result.getNsPrefixMap().putAll(model.getNsPrefixMap());
	StmtIterator it = model.listStatements();
	while (it.hasNext()) {
		Statement stmt = it.next();
		if (properties.contains(stmt.getPredicate())
				|| (stmt.getPredicate().equals(RDF.type) && classes.contains(stmt.getObject()))) {
			result.add(stmt);
		}
	}
	return result;
}
 
Example 42
Project: r2rml-kit   File: D2RQCompiler.java   Source Code and License 5 votes vote down vote up
public void visitLeave(ClassMap classMap) {
	DatabaseOp tabular = currentClassMapOpBuilder.getOp();
	for (Resource class_: classMap.getClasses()) {
		NodeMaker predicates = new FixedNodeMaker(RDF.type.asNode());
		NodeMaker objects = new FixedNodeMaker(class_.asNode());
		currentClassMapTripleRelations.add(new TripleRelation(currentSQLConnection,
				tabular, currentSubjects, predicates, objects));
	}
	result.addResourceCollection(classMap.resource().getLocalName(), 
			new ResourceCollection(result, currentSQLConnection, currentSubjects,
					tabular, currentClassMapTripleRelations));
	for (TripleRelation triples: currentClassMapTripleRelations) {
		result.addTripleRelation(triples);
	}
}
 
Example 43
Project: r2rml-kit   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 44
Project: r2rml-kit   File: ResourceCollection.java   Source Code and License 5 votes vote down vote up
private Collection<TripleRelation> filterTripleRelations(Collection<TripleRelation> entityDescription) {
	List<TripleRelation> result = new ArrayList<TripleRelation>();
	for (TripleRelation triples: entityDescription) {
		triples = triples.orderBy(TripleRelation.SUBJECT, true);
		if (!OpUtil.isEmpty(triples.selectTriple(new Triple(Node.ANY, RDF.Nodes.type, Node.ANY)).getBaseTabular())) {
			result.add(triples);
		}
		// TODO: The list of label properties is redundantly specified in PageServlet
		if (!OpUtil.isEmpty(triples.selectTriple(new Triple(Node.ANY, RDFS.label.asNode(), Node.ANY)).getBaseTabular())) {
			result.add(triples);
		} else if (!OpUtil.isEmpty(triples.selectTriple(new Triple(Node.ANY, SKOS.prefLabel.asNode(), Node.ANY)).getBaseTabular())) {
			result.add(triples);
		} else if (!OpUtil.isEmpty(triples.selectTriple(new Triple(Node.ANY, DC.title.asNode(), Node.ANY)).getBaseTabular())) {
			result.add(triples);					
		} else if (!OpUtil.isEmpty(triples.selectTriple(new Triple(Node.ANY, DCTerms.title.asNode(), Node.ANY)).getBaseTabular())) {
			result.add(triples);					
		} else if (!OpUtil.isEmpty(triples.selectTriple(new Triple(Node.ANY, FOAF.name.asNode(), Node.ANY)).getBaseTabular())) {
			result.add(triples);					
		}
	}
	if (result.isEmpty()) {
		result.add(new TripleRelation(sqlConnection, entityTable, 
				entityMaker, 
				new FixedNodeMaker(RDF.type.asNode()), 
				new FixedNodeMaker(RDFS.Resource.asNode())));
	}
	return result;
}
 
Example 45
Project: r2rml-kit   File: R2RMLReader.java   Source Code and License 5 votes vote down vote up
private LogicalTable createBaseTableOrView(Resource r) {
	if (model.contains(r, RDF.type, RR.R2RMLView)) {
		report.report(Problem.SPURIOUS_TYPE, r, RDF.type, RR.R2RMLView);
	}
	BaseTableOrView result = new BaseTableOrView();
	result.setTableName(TableOrViewName.create(getString(r, RR.tableName)));
	return result;
}
 
Example 46
Project: r2rml-kit   File: R2RMLReader.java   Source Code and License 5 votes vote down vote up
private LogicalTable createR2RMLView(Resource r) {
	if (model.contains(r, RDF.type, RR.BaseTableOrView)) {
		report.report(Problem.SPURIOUS_TYPE, r, RDF.type, RR.BaseTableOrView);
	}
	R2RMLView result = new R2RMLView();
	result.setSQLQuery(SQLQuery.create(getString(r, RR.sqlQuery)));
	for (RDFNode sqlVersion: getRDFNodes(r, RR.sqlVersion, NodeType.IRI)) {
		result.getSQLVersions().add(ConstantIRI.create(sqlVersion.asResource()));
	}
	return result;
}
 
Example 47
Project: r2rml-kit   File: R2RMLReader.java   Source Code and License 5 votes vote down vote up
private void checkForSpuriousTypes() {
	// This doesn't catch spurious subclass triples, e.g., rr:SubjectMap,
	// rr:R2RMLView.
	for (ComponentType type: ComponentType.values()) {
		ResIterator it = model.listResourcesWithProperty(RDF.type, type.asResource());
		while (it.hasNext()) {
			Resource r = it.next();
			if (mapping.getMappingComponent(r, type) == null) {
				report.report(Problem.SPURIOUS_TYPE, r, RDF.type, type.asResource());
			}
		}
	}
	remainingTriples.removeAll(null, RDF.type, (RDFNode) null);
}
 
Example 48
Project: r2rml-kit   File: R2RMLCompiler.java   Source Code and License 5 votes vote down vote up
private void visitComponent(TriplesMap triplesMap) {
	currentTable = createTabular(triplesMap);
	TermMap subjectMap = getSubjectMap(triplesMap);
	subjectMaker = createNodeMaker(
			subjectMap, Position.SUBJECT_MAP, currentTable);
	for (PredicateObjectMap poMap: mapping.predicateObjectMaps().getAll(
			triplesMap.getPredicateObjectMaps())) {
		visitComponent(poMap);
	}
	for (ConstantIRI classIRI: subjectMap.getClasses()) {
		currentTripleRelations.add(createTripleRelation(
				new FixedNodeMaker(RDF.type.asNode()),
				new FixedNodeMaker(Node.createURI(classIRI.toString())), 
				currentTable));
	}
	if (subjectMaker == null) {
		// TODO: Remove this check once we handle all term map types
		log.warn("null subject map");
	} else {
		resourceCollections.put(getTriplesMapName(), 
				new ResourceCollection(this, sqlConnection, subjectMaker, 
						createDatabaseOp(currentTable, subjectMaker.getRequiredColumns()), 
						currentTripleRelations));
	}
	tripleRelations.addAll(currentTripleRelations);
	currentTripleRelations.clear();
}
 
Example 49
Project: r2rml-kit   File: OntologyTarget.java   Source Code and License 5 votes vote down vote up
public OntologyTarget() {
	model.setNsPrefix("rdf", RDF.getURI());
	model.setNsPrefix("rdfs", RDFS.getURI());
	model.setNsPrefix("owl", OWL.getURI());
	model.setNsPrefix("dc", DC.getURI());
	model.setNsPrefix("xsd", XSD.getURI());
}
 
Example 50
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 51
Project: r2rml-kit   File: OntologyTarget.java   Source Code and License 5 votes vote down vote up
public void generateEntities(Resource class_, TableName table,
		TemplateValueMaker iriTemplate, List<Identifier> blankNodeColumns) {
	if (class_ == null) return;
	Resource c = class_.inModel(model);
	c.addProperty(RDF.type, RDFS.Class);
	c.addProperty(RDF.type, OWL.Class);
	c.addProperty(RDFS.label, getLabel(table));
	if (generatedOntology != null) {
		c.addProperty(RDFS.isDefinedBy, generatedOntology);
	}
	classes.put(table, c);
}
 
Example 52
Project: r2rml-kit   File: OntologyTarget.java   Source Code and License 5 votes vote down vote up
public void generateColumnProperty(Property property, TableName table,
		Identifier column, DataType datatype) {
	Property p = property.inModel(model);
	p.addProperty(RDF.type, RDF.Property);
	p.addProperty(RDF.type, OWL.DatatypeProperty);
	p.addProperty(RDFS.label, getLabel(table, column));
	domains.put(p, table);
	if (datatype.rdfType() != null && XSD.xstring.getURI().equals(datatype.rdfType())) {
		p.addProperty(RDFS.range, model.getResource(datatype.rdfType()));
	}
	if (generatedOntology != null) {
		p.addProperty(RDFS.isDefinedBy, generatedOntology);
	}
}
 
Example 53
Project: r2rml-kit   File: OntologyTarget.java   Source Code and License 5 votes vote down vote up
public void generateRefProperty(Property property, TableName table,
		ForeignKey foreignKey) {
	Property p = property.inModel(model);
	p.addProperty(RDF.type, RDF.Property);
	p.addProperty(RDF.type, OWL.ObjectProperty);
	p.addProperty(RDFS.label, getLabel(table, foreignKey.getLocalColumns()));
	domains.put(p, table);
	ranges.put(p, foreignKey.getReferencedTable());
	if (generatedOntology != null) {
		p.addProperty(RDFS.isDefinedBy, generatedOntology);
	}
}
 
Example 54
Project: r2rml-kit   File: OntologyTarget.java   Source Code and License 5 votes vote down vote up
public void generateLinkProperty(Property property, TableName table,
		ForeignKey fk1, ForeignKey fk2) {
	Property p = property.inModel(model);
	p.addProperty(RDF.type, RDF.Property);
	p.addProperty(RDF.type, OWL.ObjectProperty);
	p.addProperty(RDFS.label, getLabel(table));
	domains.put(p, fk1.getReferencedTable());
	ranges.put(p, fk2.getReferencedTable());
	if (generatedOntology != null) {
		p.addProperty(RDFS.isDefinedBy, generatedOntology);
	}
}
 
Example 55
Project: r2rml-kit   File: D2RQMappingStyle.java   Source Code and License 5 votes vote down vote up
public D2RQMappingStyle(SQLConnection connection, String baseIRI) {
	this.baseIRI = baseIRI;
	this.vocabBaseIRI = baseIRI + "vocab/";
	model.setNsPrefix("rdf", RDF.getURI());
	model.setNsPrefix("rdfs", RDFS.getURI());
	model.setNsPrefix("xsd", XSD.getURI());
	model.setNsPrefix("vocab", vocabBaseIRI);
	generator = new MappingGenerator(this, connection);
	generator.setGenerateLabelBridges(true);
	generator.setHandleLinkTables(true);
	generator.setGenerateDefinitionLabels(true);
	generator.setServeVocabulary(true);
	generator.setSkipForeignKeyTargetColumns(true);
	generator.setUseUniqueKeysAsEntityID(true);
}
 
Example 56
Project: r2rml-kit   File: DirectMappingStyle.java   Source Code and License 5 votes vote down vote up
public DirectMappingStyle(SQLConnection connection, String baseIRI) {
	this.generator = new MappingGenerator(this, connection);
	this.baseIRI = baseIRI;
	model.setNsPrefix("rdf", RDF.getURI());
	model.setNsPrefix("xsd", XSD.getURI());
	generator.setGenerateLabelBridges(false);
	generator.setHandleLinkTables(false);
	generator.setGenerateDefinitionLabels(false);
	generator.setServeVocabulary(false);
	generator.setSkipForeignKeyTargetColumns(false);
	generator.setUseUniqueKeysAsEntityID(false);
}
 
Example 57
Project: r2rml-kit   File: FindTest.java   Source Code and License 5 votes vote down vote up
@Test
	public void testListTypeStatements() {
		find(null, RDF.type, null);
//		dump();
		assertStatement(resource("papers/1"), RDF.type, ISWC.InProceedings);
		// Paper6 is filtered by d2rq:condition
		assertNoStatement(resource("papers/6"), RDF.type, ISWC.InProceedings);
		assertStatement(resource("conferences/23541"), RDF.type, ISWC.Conference);
		assertStatement(resource("topics/15"), RDF.type, SKOS.Concept);
		assertStatementCount(95);
	}
 
Example 58
Project: r2rml-kit   File: FindTest.java   Source Code and License 5 votes vote down vote up
@Test
	public void testListTopicInstances() {
		find(null, RDF.type, SKOS.Concept);
//		dump();
		assertStatement(resource("topics/1"), RDF.type, SKOS.Concept);
		assertStatement(resource("topics/15"), RDF.type, SKOS.Concept);
		assertStatementCount(15);
	}
 
Example 59
Project: r2rml-kit   File: FindTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testDefinitions() {
	find(ISWC.Conference, null, null);
	assertStatement(ISWC.Conference, RDF.type, RDFS.Class);
	assertStatement(ISWC.Conference, RDFS.label, createPlainLiteral("conference"));
	assertStatement(ISWC.Conference, RDFS.comment, createPlainLiteral("A conference"));
	assertStatement(ISWC.Conference, RDFS.subClassOf, ISWC.Event);
	find(RDFS.label, null, null);
	assertStatement(RDFS.label, RDF.type, RDF.Property);
	assertStatement(RDFS.label, RDFS.label, createPlainLiteral("label"));
	assertStatement(RDFS.label, RDFS.comment, createPlainLiteral("A human-readable name for the subject."));
	assertStatement(RDFS.label, RDFS.domain, RDFS.Resource);
}
 
Example 60
Project: r2rml-kit   File: HSQLDatabaseTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testGenerateTripleFromSimpleD2RQMapping() {
	Mapping m = D2RQTestUtil.loadMapping("hsqldb/simple.ttl");
	m.configuration().setServeVocabulary(false);
	db.executeSQL("INSERT INTO TEST VALUES (1, 'Hello World!')");
	GraphD2RQ g = new GraphD2RQ(m.compile());
	assertTrue(g.contains(
			Node.createURI(EX + "test/1"), RDF.Nodes.type, Node.createURI(EX + "Test")));
	assertEquals(1, g.size());
}