org.apache.jena.vocabulary.RDFS Java Examples

The following examples show how to use org.apache.jena.vocabulary.RDFS. 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: SimpleSubClassInferencerTest.java    From gerbil with GNU Affero General Public License v3.0 6 votes vote down vote up
private static Model createModel() {
    Model classModel = ModelFactory.createDefaultModel();
    Resource A = classModel.createResource("http://example.org/A");
    Resource B = classModel.createResource("http://example.org/B");
    Resource C = classModel.createResource("http://example.org/C");
    Resource C2 = classModel.createResource("http://example2.org/C");
    Resource C3 = classModel.createResource("http://example3.org/C");
    Resource D2 = classModel.createResource("http://example2.org/D");
    Resource D3 = classModel.createResource("http://example3.org/D");
    classModel.add(A, RDF.type, RDFS.Class);
    classModel.add(B, RDF.type, RDFS.Class);
    classModel.add(C, RDF.type, RDFS.Class);
    classModel.add(C2, RDF.type, RDFS.Class);
    classModel.add(C3, RDF.type, RDFS.Class);
    classModel.add(D2, RDF.type, RDFS.Class);
    classModel.add(D3, RDF.type, RDFS.Class);
    classModel.add(B, RDFS.subClassOf, A);
    classModel.add(C, RDFS.subClassOf, B);
    classModel.add(C, OWL.sameAs, C2);
    classModel.add(C3, OWL.equivalentClass, C);
    classModel.add(D2, RDFS.subClassOf, C2);
    classModel.add(D3, RDFS.subClassOf, C3);
    return classModel;
}
 
Example #2
Source File: JenaUtil.java    From shacl with Apache License 2.0 6 votes vote down vote up
private static boolean hasSuperClass(Resource subClass, Resource superClass, Set<Resource> reached) {
	StmtIterator it = subClass.listProperties(RDFS.subClassOf);
	while(it.hasNext()) {
		Statement s = it.next();
		if(superClass.equals(s.getObject())) {
			it.close();
			return true;
		}
		else if(!reached.contains(s.getResource())) {
			reached.add(s.getResource());
			if(hasSuperClass(s.getResource(), superClass, reached)) {
				it.close();
				return true;
			}
		}
	}
	return false;
}
 
Example #3
Source File: ClassHierarchyLoader.java    From gerbil with GNU Affero General Public License v3.0 6 votes vote down vote up
protected Set<Resource> getClasses(Model readModel) {
    ResIterator iterator = readModel.listSubjectsWithProperty(RDF.type, RDFS.Class);
    Resource r;
    Set<Resource> classes = new HashSet<Resource>();
    while (iterator.hasNext()) {
        r = iterator.next();
        if (!r.isAnon()) {
            classes.add(r);
        }
    }
    iterator = readModel.listSubjectsWithProperty(RDF.type, OWL.Class);
    while (iterator.hasNext()) {
        r = iterator.next();
        if (!r.isAnon()) {
            classes.add(r);
        }
    }
    return classes;
}
 
Example #4
Source File: JenaUtil.java    From shacl with Apache License 2.0 6 votes vote down vote up
private static <T> T getNearest(Resource cls, java.util.function.Function<Resource,T> function, Set<Resource> reached) {
	reached.add(cls);
	StmtIterator it = cls.listProperties(RDFS.subClassOf);
	while(it.hasNext()) {
		Statement s = it.next();
		if(s.getObject().isResource() && !reached.contains(s.getResource())) {
			T result = function.apply(s.getResource());
			if(result == null) {
				result = getNearest(s.getResource(), function, reached);
			}
			if(result != null) {
				it.close();
				return result;
			}
		}
	}
	return null;
}
 
Example #5
Source File: JenaUtil.java    From shacl with Apache License 2.0 6 votes vote down vote up
private static Resource getFirstRange(Resource property, Set<Resource> reached) {
	Resource directRange = getFirstDirectRange(property);
	if(directRange != null) {
		return directRange;
	}
	StmtIterator it = property.listProperties(RDFS.subPropertyOf);
	while (it.hasNext()) {
		Statement ss = it.next();
		if (ss.getObject().isURIResource()) {
			Resource superProperty = ss.getResource();
			if (!reached.contains(superProperty)) {
				reached.add(superProperty);
				Resource r = getFirstRange(superProperty, reached);
				if (r != null) {
					it.close();
					return r;
				}
			}
		}
	}
	return null;
}
 
Example #6
Source File: SimpleSubClassInferencer.java    From gerbil with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void inferSubClasses(String classURI, ClassSet hierarchy, ClassNodeFactory<? extends ClassNode> factory) {
    Resource classResource = new ResourceImpl(classURI);
    Set<String> alreadySeenUris = new HashSet<String>();
    addOrUpdateUri(classResource, hierarchy, factory, alreadySeenUris);

    if (!classModel.containsResource(classResource)) {
        return;
    }

    StmtIterator iterator = classModel.listStatements(null, RDFS.subClassOf, classResource);
    Statement stmt;
    Resource resource;
    while (iterator.hasNext()) {
        stmt = iterator.next();
        resource = stmt.getSubject();
        if (!alreadySeenUris.contains(resource.getURI())) {
            addOrUpdateUri(resource, hierarchy, factory, alreadySeenUris);
        }
    }
}
 
Example #7
Source File: SHSPARQLConstraintImpl.java    From shacl with Apache License 2.0 6 votes vote down vote up
@Override
   public String toString() {

	String label = JenaUtil.getStringProperty(this, RDFS.label);
	if(label != null) {
		return label;
	}
	
	String comment = JenaUtil.getStringProperty(this, RDFS.comment);
	if(comment != null) {
		return comment;
	}
	
	String message = JenaUtil.getStringProperty(this, SH.message);
	if(message != null) {
		return message;
	}

	String sparql = getSPARQL();
	if(sparql != null) {
		return sparql;
	}
	
	return "(Incomplete SPARQL Constraint)";
}
 
Example #8
Source File: SHJSConstraintImpl.java    From shacl with Apache License 2.0 6 votes vote down vote up
@Override
   public String toString() {

	String label = JenaUtil.getStringProperty(this, RDFS.label);
	if(label != null) {
		return label;
	}
	
	String comment = JenaUtil.getStringProperty(this, RDFS.comment);
	if(comment != null) {
		return comment;
	}
	
	String message = JenaUtil.getStringProperty(this, SH.message);
	if(message != null) {
		return message;
	}

	String script = getFunctionName();
	if(script != null) {
		return script;
	}
	
	return "(Incomplete JavaScript Constraint)";
}
 
Example #9
Source File: SHPropertyShapeImpl.java    From shacl with Apache License 2.0 6 votes vote down vote up
@Override
public Resource getClassOrDatatype() {
	Resource cls = getPropertyResourceValue(SH.class_);
	if(cls != null) {
		return cls;
	}
	else {
		Resource datatype = getPropertyResourceValue(SH.datatype);
		if(datatype != null) {
			return datatype;
		}
		else {
			Resource kind = getPropertyResourceValue(SH.nodeKind);
			if(SH.IRI.equals(kind) || SH.BlankNode.equals(kind)) {
				return RDFS.Resource.inModel(getModel());
			}
			else if(SH.Literal.equals(kind)) {
				return RDFS.Literal.inModel(getModel());
			}
			else {
				return null;
			}
		}
	}
}
 
Example #10
Source File: labelSearch.java    From xcurator with Apache License 2.0 6 votes vote down vote up
private QueryIterator buildSyntax(QueryIterator input, Node nodeVar, String pattern, ExecutionContext execCxt)
{
    Var var2 = createNewVar() ; 
    // Triple patterns for   ?x rdfs:label ?hiddenVar
    ElementTriplesBlock elementBGP = new ElementTriplesBlock();
    Triple t = new Triple(nodeVar, RDFS.label.asNode(), var2) ;
    elementBGP.addTriple(t) ;
    
    // Regular expression for  regex(?hiddenVar, "pattern", "i") 
    Expr regex = new E_Regex(new ExprVar(var2.getName()), pattern, "i") ;
    
    ElementGroup elementGroup = new ElementGroup() ;
    elementGroup.addElement(elementBGP) ;
    elementGroup.addElement(new ElementFilter(regex)) ;
    // Compile it.
    // The better design is to build the Op structure programmatically,
    Op op = Algebra.compile(elementGroup) ;
    op = Algebra.optimize(op, execCxt.getContext()) ;
    return QC.execute(op, input, execCxt) ;
}
 
Example #11
Source File: SHSPARQLTargetImpl.java    From shacl with Apache License 2.0 6 votes vote down vote up
@Override
   public String toString() {

	String label = JenaUtil.getStringProperty(this, RDFS.label);
	if(label != null) {
		return label;
	}
	
	String comment = JenaUtil.getStringProperty(this, RDFS.comment);
	if(comment != null) {
		return comment;
	}

	String sparql = getSPARQL();
	if(sparql != null) {
		return sparql;
	}
	
	return "(Incomplete SPARQL Target)";
}
 
Example #12
Source File: PizzaSparqlNoInf.java    From xcurator with Apache License 2.0 6 votes vote down vote up
public void run() {
    OntModel m = getModel();
    loadData( m );
    String prefix = "prefix pizza: <" + PIZZA_NS + ">\n" +
                    "prefix rdfs: <" + RDFS.getURI() + ">\n" +
                    "prefix owl: <" + OWL.getURI() + ">\n";


    showQuery( m,
               prefix +
               "select ?pizza where {?pizza a owl:Class ; " +
               "                            rdfs:subClassOf ?restriction.\n" +
               "                     ?restriction owl:onProperty pizza:hasTopping ;" +
               "                            owl:someValuesFrom pizza:PeperoniSausageTopping" +
               "}" );
}
 
Example #13
Source File: JSRule.java    From shacl with Apache License 2.0 5 votes vote down vote up
@Override
   public String toString() {
	String label = JenaUtil.getStringProperty(getResource(), RDFS.label);
	if(label == null) {
		Statement s = getResource().getProperty(SH.jsFunctionName);
		if(s != null && s.getObject().isLiteral()) {
			label = s.getString();
		}
		else {
			label = "(Missing JavaScript function name)";
		}
	}
	return getLabelStart("JavaScript") + label;
}
 
Example #14
Source File: TemplateMatcherTest.java    From Processor with Apache License 2.0 5 votes vote down vote up
@Test(expected = OntologyException.class)
public void testTemplateWithNumericalPath()
{
    Ontology invalidOntology = ModelFactory.createOntologyModel().createOntology("http://test/invalid-ontology");
    Template invalidTemplate = invalidOntology.getOntModel().createIndividual("http://test/invalid-ontology/invalid-template", LDT.Template).
            as(Template.class);
    invalidTemplate.addLiteral(LDT.match, 123).
            addProperty(RDFS.isDefinedBy, invalidOntology);
    
    matcher.match(invalidOntology, "other/something");
}
 
Example #15
Source File: SkolemizerTest.java    From Processor with Apache License 2.0 5 votes vote down vote up
@Test(expected = OntologyException.class)
public void testBuild_Resource_OntClassInvalidPath()
{
    Ontology invalidOntology = ModelFactory.createOntologyModel().createOntology("http://test/invalid");
    OntClass invalidPathClass = invalidOntology.getOntModel().createClass("http://test/invalid/path-class");
    invalidPathClass.addLiteral(LDT.path, 123).
            addProperty(RDFS.isDefinedBy, invalidOntology);
    Resource invalid = ModelFactory.createDefaultModel().createResource();
    
    URI invalidResult = skolemizer.build(invalid, invalidPathClass);
    URI invalidExp = absolutePathBuilder.clone().path(thingTitle).fragment(thingFragment).build();
    assertEquals(invalidExp, invalidResult);
}
 
Example #16
Source File: DataIDGenerator.java    From gerbil with GNU Affero General Public License v3.0 5 votes vote down vote up
public Model generateDataIDModel() {
    // create an empty JENA Model
    Model model = ModelFactory.createDefaultModel();

    // setting namespaces
    model.setNsPrefix("gerbil", GERBIL.getURI());
    model.setNsPrefix("rdf", RDF.getURI());
    model.setNsPrefix("rdfs", RDFS.getURI());
    model.setNsPrefix("xsd", XSD.getURI());
    model.setNsPrefix("qb", CUBE.getURI());

    return model;
}
 
Example #17
Source File: TemplateMatcherTest.java    From Processor with Apache License 2.0 5 votes vote down vote up
@Test(expected = OntologyException.class)
public void testTemplateWithNoPath()
{
    Ontology invalidOntology = ModelFactory.createOntologyModel().createOntology("http://test/invalid-ontology");
    Template invalidTemplate = invalidOntology.getOntModel().createIndividual("http://test/invalid-ontology/no-path-template", LDT.Template).
            as(Template.class);
    invalidTemplate.addProperty(RDFS.isDefinedBy, invalidOntology);
    
    matcher.match(invalidOntology, "other/something");
}
 
Example #18
Source File: TripleRule.java    From shacl with Apache License 2.0 5 votes vote down vote up
@Override
   public String toString() {
	String label = JenaUtil.getStringProperty(getResource(), RDFS.label);
	if(label == null) {
		label = subject.getFunctionalSyntax() + " - " + predicate.getFunctionalSyntax() + " - " + object.getFunctionalSyntax();
	}
	return getLabelStart("Triple") + label;
}
 
Example #19
Source File: OWLClassPropertyMetadataPlugin.java    From shacl with Apache License 2.0 5 votes vote down vote up
@Override
public void init(ClassPropertyMetadata cpm, Node classNode, Graph graph) {
	ExtendedIterator<Triple> it = graph.find(classNode, RDFS.subClassOf.asNode(), Node.ANY);
	while(it.hasNext()) {
		Node superClass = it.next().getObject();
		if(superClass.isBlank() && graph.contains(superClass, OWL.onProperty.asNode(), cpm.getPredicate())) {
			if(cpm.getLocalRange() == null) {
				Node localRange = JenaNodeUtil.getObject(superClass, OWL.allValuesFrom.asNode(), graph);
				if(localRange != null) {
					cpm.setLocalRange(localRange);
					it.close();
					break;
				}
			}
			if(cpm.getMaxCount() == null) {
				Node maxCountNode = JenaNodeUtil.getObject(superClass, OWL.maxCardinality.asNode(), graph);
				if(maxCountNode == null) {
					maxCountNode = JenaNodeUtil.getObject(superClass, OWL.cardinality.asNode(), graph);
				}
				if(maxCountNode != null && maxCountNode.isLiteral()) {
					Object value = maxCountNode.getLiteralValue();
					if(value instanceof Number) {
						cpm.setMaxCount(((Number) value).intValue());
					}
				}
			}
		}
	}
}
 
Example #20
Source File: DataIDGenerator.java    From gerbil with GNU Affero General Public License v3.0 5 votes vote down vote up
public Resource createExperimentResource(Model model, String eID) {
    // create experiment resource
    Resource experiment = model.createResource(gerbilURL + EXPERIMENT_PREFIX + eID);
    experiment.addProperty(RDF.type, CUBE.Dataset);
    experiment.addProperty(RDF.type, GERBIL.Experiment);

    model.add(experiment, RDFS.label, "Experiment " + eID);
    model.add(experiment, CUBE.structure, GERBIL.DSD);

    return experiment;
}
 
Example #21
Source File: DocumentInformationReducer.java    From gerbil with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Document reduceToTextAndEntities(Document document) {
    MarkingFilter<TypedNamedEntity> filter = new TypeBasedMarkingFilter<TypedNamedEntity>(false,
            RDFS.Class.getURI(), OWL.Class.getURI());
    List<TypedNamedEntity> namedEntities = document.getMarkings(TypedNamedEntity.class);
    List<Marking> markings = new ArrayList<Marking>(namedEntities.size());
    for (TypedNamedEntity tne : namedEntities) {
        if (filter.isMarkingGood(tne)) {
            markings.add(new NamedEntity(tne.getStartPosition(), tne.getLength(), tne.getUris()));
        }
    }
    return new DocumentImpl(document.getText(), document.getDocumentURI(), markings);
}
 
Example #22
Source File: DocumentInformationReducer.java    From gerbil with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Document reduceToTextAndTypedEntities(Document document) {
	 MarkingFilter<TypedNamedEntity> filter = new TypeBasedMarkingFilter<TypedNamedEntity>(false,
             RDFS.Class.getURI(), OWL.Class.getURI());
     List<TypedNamedEntity> namedEntities = document.getMarkings(TypedNamedEntity.class);
     List<Marking> markings = new ArrayList<Marking>(namedEntities.size());
     for (TypedNamedEntity tne : namedEntities) {
         if (filter.isMarkingGood(tne)) {
             markings.add(new TypedNamedEntity(tne.getStartPosition(), tne.getLength(), tne.getUris(), tne.getTypes()));
         }
     }
     return new DocumentImpl(document.getText(), document.getDocumentURI(), markings);
}
 
Example #23
Source File: HierarchicalMatchingsCounterTest.java    From gerbil with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Resource[] createResources(int numberOfResources, Model classModel) {
    Resource resources[] = new Resource[numberOfResources];
    int startChar = (int) 'A';
    for (int i = 0; i < resources.length; ++i) {
        resources[i] = classModel.createResource(KNOWN_KB_URIS[0] + ((char) (startChar + i)));
        classModel.add(resources[i], RDF.type, RDFS.Class);
    }
    return resources;
}
 
Example #24
Source File: HierarchicalFMeasureCalculatorTest.java    From gerbil with GNU Affero General Public License v3.0 5 votes vote down vote up
public static SubClassInferencer createSubClassInferencer() {
    /**
     * Creates the model:
     * 
     * <pre>
     *       A
     *     / | \
     *   B   C   D
     *  / \  |/ยด/|\`\
     * E   F G H I \ J
     *          / \|
     *         K   L
     * </pre>
     * 
     */
    CLASS_MODEL.add(RESOURCES[1], RDFS.subClassOf, RESOURCES[0]);
    CLASS_MODEL.add(RESOURCES[2], RDFS.subClassOf, RESOURCES[0]);
    CLASS_MODEL.add(RESOURCES[3], RDFS.subClassOf, RESOURCES[0]);
    CLASS_MODEL.add(RESOURCES[4], RDFS.subClassOf, RESOURCES[1]);
    CLASS_MODEL.add(RESOURCES[5], RDFS.subClassOf, RESOURCES[1]);
    CLASS_MODEL.add(RESOURCES[6], RDFS.subClassOf, RESOURCES[2]);
    CLASS_MODEL.add(RESOURCES[6], RDFS.subClassOf, RESOURCES[3]);
    CLASS_MODEL.add(RESOURCES[7], RDFS.subClassOf, RESOURCES[3]);
    CLASS_MODEL.add(RESOURCES[8], RDFS.subClassOf, RESOURCES[3]);
    CLASS_MODEL.add(RESOURCES[9], RDFS.subClassOf, RESOURCES[3]);
    CLASS_MODEL.add(RESOURCES[10], RDFS.subClassOf, RESOURCES[8]);
    CLASS_MODEL.add(RESOURCES[11], RDFS.subClassOf, RESOURCES[3]);
    CLASS_MODEL.add(RESOURCES[11], RDFS.subClassOf, RESOURCES[8]);
    return SimpleSubClassInferencerFactory.createInferencer(CLASS_MODEL);
}
 
Example #25
Source File: InstancesQueryHandler.java    From IGUANA with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Model generateTripleStats(String taskID, String resource, String property) {
	QueryStatistics qs = new QueryStatistics();
	String rdfs = "http://www.w3.org/2000/01/rdf-schema#";
	Model model = ModelFactory.createDefaultModel();

	for (File queryFile : queryFiles) {
		try {
			String query = FileUtils.readLineAt(0, queryFile);
			Query q = QueryFactory.create(query);
			qs.getStatistics(q);
			QueryStatistics qs2 = new QueryStatistics();
			qs2.getStatistics(q);

			String subject = resource + hashcode + "/" + queryFile.getName();

			model.add(model.createResource(subject), ResourceFactory.createProperty(rdfs + "ID"), queryFile.getName().replace("sparql", ""));
			model.add(model.createResource(subject), RDFS.label, query);
			model.add(model.createResource(subject), ResourceFactory.createProperty(property + "aggregations"), model.createTypedLiteral(qs2.aggr));
			model.add(model.createResource(subject), ResourceFactory.createProperty(property + "filter"), model.createTypedLiteral(qs2.filter));
			model.add(model.createResource(subject), ResourceFactory.createProperty(property + "groupBy"), model.createTypedLiteral(qs2.groupBy));
			model.add(model.createResource(subject), ResourceFactory.createProperty(property + "having"), model.createTypedLiteral(qs2.having));
			model.add(model.createResource(subject), ResourceFactory.createProperty(property + "triples"), model.createTypedLiteral(qs2.triples));
			model.add(model.createResource(subject), ResourceFactory.createProperty(property + "offset"), model.createTypedLiteral(qs2.offset));
			model.add(model.createResource(subject), ResourceFactory.createProperty(property + "optional"), model.createTypedLiteral(qs2.optional));
			model.add(model.createResource(subject), ResourceFactory.createProperty(property + "orderBy"), model.createTypedLiteral(qs2.orderBy));
			model.add(model.createResource(subject), ResourceFactory.createProperty(property + "union"), model.createTypedLiteral(qs2.union));

		} catch (IOException e) {
			LOGGER.error("[QueryHandler: {{}}] Cannot read file {{}}", this.getClass().getName(),
					queryFile.getName());
		}
	}
	return model;
}
 
Example #26
Source File: TripleBasedStorage.java    From IGUANA with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void addMetaData(Properties p) {

	String suiteUrl = getUrlWithResourcePrefix(p, COMMON.SUITE_ID_KEY);
	String expUrl = getUrlWithResourcePrefix(p, COMMON.EXPERIMENT_ID_KEY);
	String taskUrl = getUrlWithResourcePrefix(p, COMMON.EXPERIMENT_TASK_ID_KEY);
	String datasetUrl = getUrlWithResourcePrefix(p, COMMON.DATASET_ID_KEY);
	String connUrl = getUrlWithResourcePrefix(p, COMMON.CONNECTION_ID_KEY);

	metricResults.add(createStatement(suiteUrl, getUrlWithPropertyPrefix("experiment"), expUrl, true));
	metricResults.add(createStatement(suiteUrl, classUri, suiteClassUri, true));
	metricResults.add(createStatement(expUrl, getUrlWithPropertyPrefix("task"), taskUrl, true));
	metricResults.add(createStatement(expUrl, getUrlWithPropertyPrefix("dataset"), datasetUrl, true));
	metricResults.add(createStatement(expUrl, classUri, expClassUri, true));
	metricResults.add(createStatement(taskUrl, getUrlWithPropertyPrefix("connection"), connUrl, true));
	metricResults.add(createStatement(taskUrl, classUri, taskClassUri, true));
	addExtraMetadata(p, taskUrl);
	metricResults.add(metricResults.createResource(datasetUrl), RDFS.label, p.getProperty(COMMON.DATASET_ID_KEY));
	metricResults.add(metricResults.createResource(connUrl), RDFS.label, p.getProperty(COMMON.CONNECTION_ID_KEY));

	if(p.containsKey(COMMON.QUERY_STATS)) {
		Model queryStats = (Model) p.get(COMMON.QUERY_STATS);
		metricResults.add(queryStats);
	}

	Calendar cal = GregorianCalendar.getInstance();
	metricResults.add(metricResults.createResource(taskUrl),
			ResourceFactory.createProperty(rdfsUri + "startDate"), metricResults.createTypedLiteral(cal));
}
 
Example #27
Source File: labelSearch.java    From xcurator with Apache License 2.0 5 votes vote down vote up
private static Model make()
{
    String BASE = "http://example/" ;
    Model model = ModelFactory.createDefaultModel() ;
    model.setNsPrefix("", BASE) ;
    Resource r1 = model.createResource(BASE+"r1") ;
    Resource r2 = model.createResource(BASE+"r2") ;

    r1.addProperty(RDFS.label, "abc") ;
    r2.addProperty(RDFS.label, "def") ;

    return model  ;
}
 
Example #28
Source File: HelloWorld.java    From xcurator with Apache License 2.0 5 votes vote down vote up
/**
 * Get the English-language label for a given resource. In general, a resource
 * may have zero, one or many labels. In this case, we happen to know that
 * the cheese resources have mutlilingual labels, so we pick out the English one
 * @param cheese
 * @return
 */
protected String getEnglishLabel( Resource cheese ) {
    StmtIterator i = cheese.listProperties( RDFS.label );
    while (i.hasNext()) {
        Literal l = i.next().getLiteral();

        if (l.getLanguage() != null && l.getLanguage().equals( "en")) {
            // found the English language label
            return l.getLexicalForm();
        }
    }

    return "A Cheese with No Name!";
}
 
Example #29
Source File: BatchShapeTargetReader.java    From RDFUnit with Apache License 2.0 5 votes vote down vote up
private List<ShapeTarget> collectImplicitClassTarget(Resource resource) {
    if (resource.hasProperty(RDF.type, RDFS.Class) || resource.hasProperty(RDF.type, OWL.Class)) {
        return Collections.singletonList(
                ShapeTargetCore.create(ShapeTargetType.ClassTarget, resource
        ));
    } else {
        return Collections.emptyList();
    }
}
 
Example #30
Source File: PropertyValuePairSetTest.java    From RDFUnit with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetAnnotations() {

    //add rdf:type rdfs:Class
    PropertyValuePairSet.PropertyValuePairSetBuilder an1 = PropertyValuePairSet.builder();
    an1.annotation(PropertyValuePair.create(RDF.type, RDFS.Class));
    assertThat(an1.build().getAnnotations().size())
            .isEqualTo(1);
    assertThat(an1.build().contains(RDF.type)).isTrue();
    assertThat(an1.build().contains(RDF.first)).isFalse();
    assertThat(an1.build().getPropertyValues(RDF.type))
            .isNotEmpty()
            .hasSize(1);
    assertThat(an1.build().getPropertyValues(RDF.first)).isEmpty();
    List<PropertyValuePair> annotations = new ArrayList<>(an1.build().getAnnotations());
    assertThat(annotations.get(0).getProperty())
            .isEqualTo(RDF.type);
    assertThat(annotations.get(0).getValues().size())
            .isEqualTo(1);
    assertThat(((new ArrayList<>(annotations.get(0).getValues())).get(0)))
            .isEqualTo(RDFS.Class);

    //add rdf:type rdfs:Literal
    an1.annotation(PropertyValuePair.create(RDF.type, RDFS.Literal));
    assertThat(an1.build().getAnnotations().size())
            .isEqualTo(1);
    annotations = new ArrayList<>(an1.build().getAnnotations());
    assertThat(annotations.get(0).getProperty())
            .isEqualTo(RDF.type);
    assertThat(annotations.get(0).getValues().size())
            .isEqualTo(2);

    //add rdf:subject rdfs:Datatype
    an1.annotation(PropertyValuePair.create(RDF.subject, RDFS.Datatype));
    assertThat(an1.build().getAnnotations().size())
            .isEqualTo(2);


}