org.eclipse.rdf4j.model.vocabulary.SKOS Java Examples

The following examples show how to use org.eclipse.rdf4j.model.vocabulary.SKOS. 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: TestFixtures.java    From inception with Apache License 2.0 6 votes vote down vote up
public KnowledgeBase buildKnowledgeBase(Project project, String name, Reification reification)
{
    KnowledgeBase kb = new KnowledgeBase();
    kb.setName(name);
    kb.setProject(project);
    kb.setType(RepositoryType.LOCAL);
    kb.setClassIri(RDFS.CLASS);
    kb.setSubclassIri(RDFS.SUBCLASSOF);
    kb.setTypeIri(RDF.TYPE);
    kb.setLabelIri(RDFS.LABEL);
    kb.setPropertyTypeIri(RDF.PROPERTY);
    kb.setDescriptionIri(RDFS.COMMENT);
    kb.setSubPropertyIri(RDFS.SUBPROPERTYOF);
    kb.setFullTextSearchIri(IriConstants.FTS_LUCENE);
    // Intentionally using different IRIs for label/description and property-label/description
    // to detect cases where we accidentally construct queries using the wrong mapping, e.g.
    // querying for properties with the class label.
    kb.setPropertyLabelIri(SKOS.PREF_LABEL);
    kb.setPropertyDescriptionIri(SKOS.DEFINITION);
    kb.setRootConcepts(new ArrayList<>());
    kb.setReification(reification);
    kb.setMaxResults(1000);
    kb.setDefaultLanguage("en");
    return kb;
}
 
Example #2
Source File: NamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.util.Namespaces#asMap(java.util.Set)}.
 */
@Test
public final void testAsMapMultiple() {
	Set<Namespace> input = new HashSet<>();
	input.add(new SimpleNamespace(RDF.PREFIX, RDF.NAMESPACE));
	input.add(new SimpleNamespace(RDFS.PREFIX, RDFS.NAMESPACE));
	input.add(new SimpleNamespace(DC.PREFIX, DC.NAMESPACE));
	input.add(new SimpleNamespace(SKOS.PREFIX, SKOS.NAMESPACE));
	input.add(new SimpleNamespace(SESAME.PREFIX, SESAME.NAMESPACE));

	Map<String, String> map = Namespaces.asMap(input);

	assertFalse(map.isEmpty());
	assertEquals(5, map.size());

	assertTrue(map.containsKey(RDF.PREFIX));
	assertEquals(RDF.NAMESPACE, map.get(RDF.PREFIX));
	assertTrue(map.containsKey(RDFS.PREFIX));
	assertEquals(RDFS.NAMESPACE, map.get(RDFS.PREFIX));
	assertTrue(map.containsKey(DC.PREFIX));
	assertEquals(DC.NAMESPACE, map.get(DC.PREFIX));
	assertTrue(map.containsKey(SKOS.PREFIX));
	assertEquals(SKOS.NAMESPACE, map.get(SKOS.PREFIX));
	assertTrue(map.containsKey(SESAME.PREFIX));
	assertEquals(SESAME.NAMESPACE, map.get(SESAME.PREFIX));
}
 
Example #3
Source File: LocalReasonerTest.java    From rya with Apache License 2.0 6 votes vote down vote up
/**
 * prp-symp
 */
@Test
public void testSymmetry() throws Exception {
    schema.processTriple(TestUtils.statement(SKOS.RELATED, RDF.TYPE,
        OWL.SYMMETRICPROPERTY));
    reasoner.processFact(TestUtils.fact(TestUtils.uri("y"), SKOS.RELATED,
        TestUtils.NODE));
    for (Fact t : reasoner.getFacts()) {
        if (t.getSubject().equals(TestUtils.NODE)
            && t.getPredicate().equals(SKOS.RELATED)
            && t.getObject().equals(TestUtils.uri("y"))) {
            return;
        }
    }
    Assert.fail("Symmetric property not inferred");
}
 
Example #4
Source File: ModelNamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.Model#removeNamespace(java.lang.String)}.
 */
@Test
public final void testRemoveNamespaceSingle() {
	testModel.setNamespace(DC.PREFIX, DC.NAMESPACE);

	Set<Namespace> namespaces = testModel.getNamespaces();

	assertNotNull("Namespaces set must not be null", namespaces);
	assertFalse(namespaces.isEmpty());
	assertEquals(1, namespaces.size());

	assertTrue("Did not find the expected namespace in the set",
			namespaces.contains(new SimpleNamespace(DC.PREFIX, DC.NAMESPACE)));

	assertFalse(testModel.removeNamespace(RDF.NAMESPACE).isPresent());
	assertFalse(testModel.removeNamespace(RDFS.NAMESPACE).isPresent());
	assertEquals(new SimpleNamespace(DC.PREFIX, DC.NAMESPACE), testModel.removeNamespace(DC.PREFIX).get());
	assertFalse(testModel.removeNamespace(SKOS.NAMESPACE).isPresent());
	assertFalse(testModel.removeNamespace(SESAME.NAMESPACE).isPresent());

	Set<Namespace> namespacesAfter = testModel.getNamespaces();

	assertNotNull("Namespaces set must not be null", namespacesAfter);
	assertTrue("Namespaces must now be empty", namespacesAfter.isEmpty());
}
 
Example #5
Source File: ModelNamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.Model#setNamespace(org.eclipse.rdf4j.model.Namespace)}.
 */
@Test
public final void testSetNamespaceNamespace() {
	testModel.setNamespace(new SimpleNamespace(RDF.PREFIX, RDF.NAMESPACE));
	testModel.setNamespace(new SimpleNamespace(RDFS.PREFIX, RDFS.NAMESPACE));
	testModel.setNamespace(new SimpleNamespace(DC.PREFIX, DC.NAMESPACE));
	testModel.setNamespace(new SimpleNamespace(SKOS.PREFIX, SKOS.NAMESPACE));
	testModel.setNamespace(new SimpleNamespace(SESAME.PREFIX, SESAME.NAMESPACE));

	Set<Namespace> namespaces = testModel.getNamespaces();

	assertNotNull("Namespaces set must not be null", namespaces);
	assertFalse(namespaces.isEmpty());
	assertEquals(5, namespaces.size());

	assertEquals(new SimpleNamespace(RDF.PREFIX, RDF.NAMESPACE), testModel.getNamespace(RDF.PREFIX).get());
	assertEquals(new SimpleNamespace(RDFS.PREFIX, RDFS.NAMESPACE), testModel.getNamespace(RDFS.PREFIX).get());
	assertEquals(new SimpleNamespace(DC.PREFIX, DC.NAMESPACE), testModel.getNamespace(DC.PREFIX).get());
	assertEquals(new SimpleNamespace(SKOS.PREFIX, SKOS.NAMESPACE), testModel.getNamespace(SKOS.PREFIX).get());
	assertEquals(new SimpleNamespace(SESAME.PREFIX, SESAME.NAMESPACE), testModel.getNamespace(SESAME.PREFIX).get());
}
 
Example #6
Source File: ModelNamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.Model#getNamespace(java.lang.String)}.
 */
@Test
public final void testGetNamespaceMultiple() {
	testModel.setNamespace(RDF.PREFIX, RDF.NAMESPACE);
	testModel.setNamespace(RDFS.PREFIX, RDFS.NAMESPACE);
	testModel.setNamespace(DC.PREFIX, DC.NAMESPACE);
	testModel.setNamespace(SKOS.PREFIX, SKOS.NAMESPACE);
	testModel.setNamespace(SESAME.PREFIX, SESAME.NAMESPACE);

	Set<Namespace> namespaces = testModel.getNamespaces();

	assertNotNull("Namespaces set must not be null", namespaces);
	assertFalse(namespaces.isEmpty());
	assertEquals(5, namespaces.size());

	assertEquals(new SimpleNamespace(RDF.PREFIX, RDF.NAMESPACE), testModel.getNamespace(RDF.PREFIX).get());
	assertEquals(new SimpleNamespace(RDFS.PREFIX, RDFS.NAMESPACE), testModel.getNamespace(RDFS.PREFIX).get());
	assertEquals(new SimpleNamespace(DC.PREFIX, DC.NAMESPACE), testModel.getNamespace(DC.PREFIX).get());
	assertEquals(new SimpleNamespace(SKOS.PREFIX, SKOS.NAMESPACE), testModel.getNamespace(SKOS.PREFIX).get());
	assertEquals(new SimpleNamespace(SESAME.PREFIX, SESAME.NAMESPACE), testModel.getNamespace(SESAME.PREFIX).get());
}
 
Example #7
Source File: ModelNamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.Model#getNamespace(java.lang.String)}.
 */
@Test
public final void testGetNamespaceSingle() {
	testModel.setNamespace(RDFS.PREFIX, RDFS.NAMESPACE);

	Set<Namespace> namespaces = testModel.getNamespaces();

	assertNotNull("Namespaces set must not be null", namespaces);
	assertFalse(namespaces.isEmpty());
	assertEquals(1, namespaces.size());

	assertTrue("Did not find the expected namespace in the set",
			namespaces.contains(new SimpleNamespace(RDFS.PREFIX, RDFS.NAMESPACE)));

	assertFalse(testModel.getNamespace(RDF.PREFIX).isPresent());
	assertEquals(new SimpleNamespace(RDFS.PREFIX, RDFS.NAMESPACE), testModel.getNamespace(RDFS.PREFIX).get());
	assertFalse(testModel.getNamespace(DC.PREFIX).isPresent());
	assertFalse(testModel.getNamespace(SKOS.PREFIX).isPresent());
	assertFalse(testModel.getNamespace(SESAME.PREFIX).isPresent());
}
 
Example #8
Source File: SPARQLQueryBuilderTest.java    From inception with Apache License 2.0 6 votes vote down vote up
private void initRdfsMapping()
{
    ValueFactory vf = SimpleValueFactory.getInstance();
    
    kb.setClassIri(RDFS.CLASS);
    kb.setSubclassIri(RDFS.SUBCLASSOF);
    kb.setTypeIri(RDF.TYPE);
    kb.setLabelIri(RDFS.LABEL);
    kb.setPropertyTypeIri(RDF.PROPERTY);
    kb.setDescriptionIri(RDFS.COMMENT);
    // We are intentionally not using RDFS.LABEL here to ensure we can test the label
    // and property label separately
    kb.setPropertyLabelIri(SKOS.PREF_LABEL);        
    // We are intentionally not using RDFS.COMMENT here to ensure we can test the description
    // and property description separately
    kb.setPropertyDescriptionIri(vf.createIRI("http://schema.org/description"));
    kb.setSubPropertyIri(RDFS.SUBPROPERTYOF);
}
 
Example #9
Source File: ModelNamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.Model#getNamespaces()}.
 */
@Test
public final void testGetNamespacesMultiple() {
	testModel.setNamespace(RDF.PREFIX, RDF.NAMESPACE);
	testModel.setNamespace(RDFS.PREFIX, RDFS.NAMESPACE);
	testModel.setNamespace(DC.PREFIX, DC.NAMESPACE);
	testModel.setNamespace(SKOS.PREFIX, SKOS.NAMESPACE);
	testModel.setNamespace(SESAME.PREFIX, SESAME.NAMESPACE);

	Set<Namespace> namespaces = testModel.getNamespaces();

	assertNotNull("Namespaces set must not be null", namespaces);
	assertFalse(namespaces.isEmpty());
	assertEquals(5, namespaces.size());

	assertTrue(namespaces.contains(new SimpleNamespace(RDF.PREFIX, RDF.NAMESPACE)));
	assertTrue(namespaces.contains(new SimpleNamespace(RDFS.PREFIX, RDFS.NAMESPACE)));
	assertTrue(namespaces.contains(new SimpleNamespace(DC.PREFIX, DC.NAMESPACE)));
	assertTrue(namespaces.contains(new SimpleNamespace(SKOS.PREFIX, SKOS.NAMESPACE)));
	assertTrue(namespaces.contains(new SimpleNamespace(SESAME.PREFIX, SESAME.NAMESPACE)));
}
 
Example #10
Source File: NoReificationTest.java    From inception with Apache License 2.0 6 votes vote down vote up
private void initRdfsMapping()
{
    ValueFactory vf = SimpleValueFactory.getInstance();
    
    kb.setClassIri(RDFS.CLASS);
    kb.setSubclassIri(RDFS.SUBCLASSOF);
    kb.setTypeIri(RDF.TYPE);
    kb.setLabelIri(RDFS.LABEL);
    kb.setPropertyTypeIri(RDF.PROPERTY);
    kb.setDescriptionIri(RDFS.COMMENT);
    // We are intentionally not using RDFS.LABEL here to ensure we can test the label
    // and property label separately
    kb.setPropertyLabelIri(SKOS.PREF_LABEL);        
    // We are intentionally not using RDFS.COMMENT here to ensure we can test the description
    // and property description separately
    kb.setPropertyDescriptionIri(vf.createIRI("http://schema.org/description"));
    kb.setSubPropertyIri(RDFS.SUBPROPERTYOF);
}
 
Example #11
Source File: SchemaTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testInputDisjointClassReverse() throws Exception {
    Schema schema = new Schema();
    schema.processTriple(TestUtils.statement(SKOS.CONCEPT,
        OWL.DISJOINTWITH, SKOS.COLLECTION));
    Assert.assertTrue("(x disjointWith y): x not found in y's disjoint classes",
        schema.getClass(SKOS.COLLECTION).getDisjointClasses().contains(SKOS.CONCEPT));
}
 
Example #12
Source File: SchemaTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testInputDisjointClass() throws Exception {
    Schema schema = new Schema();
    schema.processTriple(TestUtils.statement(SKOS.CONCEPT,
        OWL.DISJOINTWITH, SKOS.COLLECTION));
    Assert.assertTrue("(x disjointWith y): y not found in x's disjoint classes",
        schema.getClass(SKOS.CONCEPT).getDisjointClasses().contains(SKOS.COLLECTION));
}
 
Example #13
Source File: LocalReasonerTest.java    From rya with Apache License 2.0 5 votes vote down vote up
/**
 * cax-dw
 */
@Test
public void testDisjointClasses() throws Exception {
    schema.processTriple(TestUtils.statement(SKOS.CONCEPT, OWL.DISJOINTWITH,
        SKOS.COLLECTION));
    reasoner.processFact(TestUtils.fact(TestUtils.NODE, RDF.TYPE,
        SKOS.CONCEPT));
    reasoner.processFact(TestUtils.fact(TestUtils.NODE, RDF.TYPE,
        SKOS.COLLECTION));
    Assert.assertTrue("Disjoint class membership not detected",
        reasoner.hasInconsistencies());
}
 
Example #14
Source File: SchemaTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testInputSymmetric() throws Exception {
    Schema schema = new Schema();
    schema.processTriple(TestUtils.statement(SKOS.RELATED,
        RDF.TYPE, OWL.SYMMETRICPROPERTY));
    Assert.assertTrue("Property should be identified as symmetric",
        schema.getProperty(SKOS.RELATED).isSymmetric());
}
 
Example #15
Source File: SimpleOntologyTest.java    From mobi with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void getIndividualsOfTypeDeclaredTest() throws Exception {
    // Setup:
    OClass clazz = new SimpleClass(vf.createIRI(SKOS.CONCEPT.stringValue()));
    Set<String> expectedIndividuals = Stream.of("http://mobi.com/ontology/only-declared#ConceptA").collect(Collectors.toSet());

    Set<Individual> individuals = onlyDeclared.getIndividualsOfType(clazz);
    assertEquals(expectedIndividuals.size(), individuals.size());
    individuals.stream()
            .map(individual -> individual.getIRI().stringValue())
            .forEach(iri -> assertTrue(expectedIndividuals.contains(iri)));
}
 
Example #16
Source File: SimpleOntologyTest.java    From mobi with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void getIndividualsOfTypeIRIDeclaredTest() {
    // Setup:
    Set<String> expectedIndividuals = Stream.of("http://mobi.com/ontology/only-declared#ConceptA").collect(Collectors.toSet());

    Set<Individual> individuals = onlyDeclared.getIndividualsOfType(vf.createIRI(SKOS.CONCEPT.stringValue()));
    assertEquals(expectedIndividuals.size(), individuals.size());
    individuals.stream()
            .map(individual -> individual.getIRI().stringValue())
            .forEach(iri -> assertTrue(expectedIndividuals.contains(iri)));
}
 
Example #17
Source File: FullSimpleOntologyTest.java    From mobi with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void getIndividualsOfTypeDeclaredTest() throws Exception {
    // Setup:
    OClass clazz = new SimpleClass(vf.createIRI(SKOS.CONCEPT.stringValue()));
    Set<String> expectedIndividuals = Stream.of("http://mobi.com/ontology/only-declared#ConceptA").collect(Collectors.toSet());

    Set<Individual> individuals = onlyDeclared.getIndividualsOfType(clazz);
    assertEquals(expectedIndividuals.size(), individuals.size());
    individuals.stream()
            .map(individual -> individual.getIRI().stringValue())
            .forEach(iri -> assertTrue(expectedIndividuals.contains(iri)));
}
 
Example #18
Source File: FullSimpleOntologyTest.java    From mobi with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void getIndividualsOfTypeIRIDeclaredTest() {
    // Setup:
    Set<String> expectedIndividuals = Stream.of("http://mobi.com/ontology/only-declared#ConceptA").collect(Collectors.toSet());

    Set<Individual> individuals = onlyDeclared.getIndividualsOfType(vf.createIRI(SKOS.CONCEPT.stringValue()));
    assertEquals(expectedIndividuals.size(), individuals.size());
    individuals.stream()
            .map(individual -> individual.getIRI().stringValue())
            .forEach(iri -> assertTrue(expectedIndividuals.contains(iri)));
}
 
Example #19
Source File: CustomTurtleParserTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testParsingNamespacesWithOverride() throws Exception {
	ParserConfig aConfig = new ParserConfig();

	aConfig.set(BasicParserSettings.NAMESPACES,
			Collections.<Namespace>singleton(new NamespaceImpl("foo", SKOS.NAMESPACE)));

	Model model = Rio.parse(new StringReader("@prefix skos : <urn:not_skos:> ." + "<urn:a> skos:broader <urn:b>."),
			"", RDFFormat.TURTLE, aConfig, vf, new ParseErrorLogger());

	assertEquals(1, model.size());
	assertTrue(model.contains(vf.createIRI("urn:a"), vf.createIRI("urn:not_skos:broader"), vf.createIRI("urn:b")));
}
 
Example #20
Source File: CustomTurtleParserTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testParsingNamespacesWithOption() throws Exception {
	ParserConfig aConfig = new ParserConfig();

	aConfig.set(BasicParserSettings.NAMESPACES,
			Collections.<Namespace>singleton(new NamespaceImpl("foo", SKOS.NAMESPACE)));

	Model model = Rio.parse(new StringReader("<urn:a> foo:broader <urn:b>."), "", RDFFormat.TURTLE, aConfig, vf,
			new ParseErrorLogger());

	assertEquals(1, model.size());
	assertTrue(model.contains(vf.createURI("urn:a"), SKOS.BROADER, vf.createURI("urn:b")));
}
 
Example #21
Source File: CustomTurtleParserTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testParsingDefaultNamespaces() throws Exception {
	Model model = Rio.parse(new StringReader("<urn:a> skos:broader <urn:b>."), "", RDFFormat.TURTLE);

	assertEquals(1, model.size());
	assertTrue(model.contains(vf.createURI("urn:a"), SKOS.BROADER, vf.createURI("urn:b")));
}
 
Example #22
Source File: PropertyPathTests.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@BeforeEach
public void before() {
	QueryManager qm = federationContext().getQueryManager();
	qm.addPrefixDeclaration("owl", OWL.NAMESPACE);
	qm.addPrefixDeclaration("rdfs", RDFS.NAMESPACE);
	qm.addPrefixDeclaration("skos", SKOS.NAMESPACE);
	qm.addPrefixDeclaration("foaf", FOAF.NAMESPACE);
	qm.addPrefixDeclaration("", EXAMPLE_NAMESPACE);
}
 
Example #23
Source File: ModelNamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.Model#removeNamespace(java.lang.String)}.
 */
@Test
public final void testRemoveNamespaceMultiple() {
	testModel.setNamespace(new SimpleNamespace(RDF.PREFIX, RDF.NAMESPACE));
	testModel.setNamespace(new SimpleNamespace(RDFS.PREFIX, RDFS.NAMESPACE));
	testModel.setNamespace(new SimpleNamespace(DC.PREFIX, DC.NAMESPACE));
	testModel.setNamespace(new SimpleNamespace(SKOS.PREFIX, SKOS.NAMESPACE));
	testModel.setNamespace(new SimpleNamespace(SESAME.PREFIX, SESAME.NAMESPACE));

	Set<Namespace> namespaces = testModel.getNamespaces();

	assertNotNull("Namespaces set must not be null", namespaces);
	assertFalse(namespaces.isEmpty());
	assertEquals(5, namespaces.size());

	assertEquals(new SimpleNamespace(RDF.PREFIX, RDF.NAMESPACE), testModel.removeNamespace(RDF.PREFIX).get());
	assertEquals(new SimpleNamespace(RDFS.PREFIX, RDFS.NAMESPACE), testModel.removeNamespace(RDFS.PREFIX).get());
	assertEquals(new SimpleNamespace(DC.PREFIX, DC.NAMESPACE), testModel.removeNamespace(DC.PREFIX).get());
	assertEquals(new SimpleNamespace(SKOS.PREFIX, SKOS.NAMESPACE), testModel.removeNamespace(SKOS.PREFIX).get());
	assertEquals(new SimpleNamespace(SESAME.PREFIX, SESAME.NAMESPACE),
			testModel.removeNamespace(SESAME.PREFIX).get());

	Set<Namespace> namespacesAfter = testModel.getNamespaces();

	assertNotNull("Namespaces set must not be null", namespacesAfter);
	assertTrue("Namespaces must now be empty", namespacesAfter.isEmpty());
}
 
Example #24
Source File: ModelNamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.Model#removeNamespace(java.lang.String)}.
 */
@Test
public final void testRemoveNamespaceEmpty() {
	Set<Namespace> namespaces = testModel.getNamespaces();

	assertNotNull("Namespaces set must not be null", namespaces);
	assertTrue("Namespaces must initially be empty", namespaces.isEmpty());

	assertFalse(testModel.removeNamespace(RDF.NAMESPACE).isPresent());
	assertFalse(testModel.removeNamespace(RDFS.NAMESPACE).isPresent());
	assertFalse(testModel.removeNamespace(DC.NAMESPACE).isPresent());
	assertFalse(testModel.removeNamespace(SKOS.NAMESPACE).isPresent());
	assertFalse(testModel.removeNamespace(SESAME.NAMESPACE).isPresent());
}
 
Example #25
Source File: ModelNamespacesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Test method for {@link org.eclipse.rdf4j.model.Model#getNamespace(java.lang.String)}.
 */
@Test
public final void testGetNamespaceEmpty() {
	Set<Namespace> namespaces = testModel.getNamespaces();

	assertNotNull("Namespaces set must not be null", namespaces);
	assertTrue("Namespaces must initially be empty", namespaces.isEmpty());

	assertFalse(testModel.getNamespace(RDF.PREFIX).isPresent());
	assertFalse(testModel.getNamespace(RDFS.PREFIX).isPresent());
	assertFalse(testModel.getNamespace(DC.PREFIX).isPresent());
	assertFalse(testModel.getNamespace(SKOS.PREFIX).isPresent());
	assertFalse(testModel.getNamespace(SESAME.PREFIX).isPresent());
}
 
Example #26
Source File: OntologyRest.java    From mobi with GNU Affero General Public License v3.0 4 votes vote down vote up
private ArrayNode getDerivedConceptTypeIRIArray(Ontology ontology) {
    return irisToJsonArray(ontology.getSubClassesFor(sesameTransformer.mobiIRI(SKOS.CONCEPT)));
}
 
Example #27
Source File: OntologyRest.java    From mobi with GNU Affero General Public License v3.0 4 votes vote down vote up
private ArrayNode getDerivedConceptSchemeTypeIRIArray(Ontology ontology) {
    return irisToJsonArray(ontology.getSubClassesFor(sesameTransformer.mobiIRI(SKOS.CONCEPT_SCHEME)));
}
 
Example #28
Source File: OntologyRest.java    From mobi with GNU Affero General Public License v3.0 4 votes vote down vote up
private ArrayNode getDerivedSemanticRelationIRIArray(Ontology ontology) {
    return irisToJsonArray(ontology.getSubPropertiesFor(sesameTransformer.mobiIRI(SKOS.SEMANTIC_RELATION)));
}
 
Example #29
Source File: SimpleOntology.java    From mobi with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Hierarchy getConceptRelationships(ValueFactory vf, ModelFactory mf) {
    long start = getStartTime();
    try {
        Hierarchy hierarchy = new Hierarchy(vf, mf);

        OWLClass conceptClass = owlManager.getOWLDataFactory()
                .getOWLClass(org.semanticweb.owlapi.model.IRI.create(CONCEPT));
        owlReasoner.instances(conceptClass)
                .filter(this::isDeclaredIndividual)
                .forEach(concept -> {
                    IRI conceptIRI = SimpleOntologyValues.mobiIRI(concept.getIRI());
                    hierarchy.addIRI(conceptIRI);

                    Set<IRI> superConcepts = new HashSet<>();
                    Set<IRI> subConcepts = new HashSet<>();
                    owlOntology.axioms(concept, Imports.INCLUDED)
                            .filter(axiom -> axiom.getAxiomType() == AxiomType.OBJECT_PROPERTY_ASSERTION)
                            .map(axiom -> (OWLObjectPropertyAssertionAxiom) axiom)
                            .forEach(axiom -> {
                                String property = axiom.getProperty().getNamedProperty().toStringID();
                                if (property.equals(SKOS.NARROWER.stringValue())
                                        || property.equals(SKOS.NARROWER_TRANSITIVE.stringValue())
                                        || property.equals(SKOS.NARROW_MATCH.stringValue())) {
                                    IRI subConceptIRI = SimpleOntologyValues.mobiIRI(
                                            org.semanticweb.owlapi.model.IRI.create(axiom.getObject()
                                                    .toStringID()));
                                    if (!subConceptIRI.equals(conceptIRI)
                                            && isDeclaredIndividual(axiom.getObject())) {
                                        subConcepts.add(subConceptIRI);
                                    }
                                } else if (property.equals(SKOS.BROADER.stringValue())
                                        || property.equals(SKOS.BROADER_TRANSITIVE.stringValue())
                                        || property.equals(SKOS.BROAD_MATCH.stringValue())) {
                                    IRI superConceptIRI = SimpleOntologyValues.mobiIRI(
                                            org.semanticweb.owlapi.model.IRI.create(axiom.getObject()
                                                    .toStringID()));
                                    if (!superConceptIRI.equals(conceptIRI)
                                            && isDeclaredIndividual(axiom.getObject())) {
                                        superConcepts.add(superConceptIRI);
                                    }
                                }
                            });

                    superConcepts.forEach(iri -> hierarchy.addParentChild(iri, conceptIRI));
                    subConcepts.forEach(iri -> hierarchy.addParentChild(conceptIRI, iri));
                });

        return hierarchy;
    } finally {
        logTrace("getConceptRelationships()", start);
    }
}
 
Example #30
Source File: RDFWriterTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void testPerformanceInternal(boolean storeParsedStatements) throws Exception {

		Random prng = new Random(this.getClass().getName().hashCode());
		Model model = new LinkedHashModel();

		for (int i = 0; i < 10000; i++) {

			Value obj = potentialObjects.get(prng.nextInt(potentialObjects.size()));
			if (obj == litBigPlaceholder) {
				StringBuilder big = new StringBuilder();
				int len = 25000 + prng.nextInt(5000);
				for (int j = 0; j < len; j++) {
					big.append(((char) (32 + prng.nextInt(90))));
				}
				obj = vf.createLiteral(big.toString());
			}

			IRI pred = potentialPredicates.get(prng.nextInt(potentialPredicates.size()));
			while (obj instanceof Triple && pred.equals(RDF.TYPE)) {
				// Avoid statements "x rdf:type <<triple>>" as those use the shorter syntax in RDFXMLPrettyWriter
				// and the writer produces invalid XML in that case. Even though the RDF* triples are encoded as
				// valid IRIs, XML has limitations on what characters may form an XML tag name and thus a limitation
				// on what IRIs may be used in predicates (predicates are XML tags) or the short form of rdf:type
				// (where the type is also an XML tag).
				obj = potentialObjects.get(prng.nextInt(potentialObjects.size()));
			}
			model.add(potentialSubjects.get(prng.nextInt(potentialSubjects.size())),
					pred, obj);
		}
		logger.debug("Test class: " + this.getClass().getName());
		logger.debug("Test statements size: " + model.size() + " (" + rdfWriterFactory.getRDFFormat() + ")");
		assertFalse("Did not generate any test statements", model.isEmpty());

		File testFile = tempDir.newFile("performancetest." + rdfWriterFactory.getRDFFormat().getDefaultFileExtension());

		try (OutputStream out = new BufferedOutputStream(new FileOutputStream(testFile))) {

			long startWrite = System.currentTimeMillis();
			RDFWriter rdfWriter = rdfWriterFactory.getWriter(out);
			setupWriterConfig(rdfWriter.getWriterConfig());
			// Test prefixed URIs for only some of the URIs available
			rdfWriter.startRDF();
			rdfWriter.handleNamespace(RDF.PREFIX, RDF.NAMESPACE);
			rdfWriter.handleNamespace(SKOS.PREFIX, SKOS.NAMESPACE);
			rdfWriter.handleNamespace(FOAF.PREFIX, FOAF.NAMESPACE);
			rdfWriter.handleNamespace(EARL.PREFIX, EARL.NAMESPACE);
			rdfWriter.handleNamespace("ex", exNs);

			for (Statement nextSt : model) {
				rdfWriter.handleStatement(nextSt);
			}

			rdfWriter.endRDF();
			long endWrite = System.currentTimeMillis();
			logger.debug(
					"Write took: " + (endWrite - startWrite) + " ms (" + rdfWriterFactory.getRDFFormat() + ")");
			logger.debug("File size (bytes): " + testFile.length());

		}

		try (InputStream in = new BufferedInputStream(new FileInputStream(testFile))) {

			RDFParser rdfParser = rdfParserFactory.getParser();
			setupParserConfig(rdfParser.getParserConfig());
			rdfParser.setValueFactory(vf);
			Model parsedModel = new LinkedHashModel();
			if (storeParsedStatements) {
				rdfParser.setRDFHandler(new StatementCollector(parsedModel));
			}
			long startParse = System.currentTimeMillis();
			rdfParser.parse(in, "foo:bar");
			long endParse = System.currentTimeMillis();
			logger.debug(
					"Parse took: " + (endParse - startParse) + " ms (" + rdfParserFactory.getRDFFormat() + ")");

			if (storeParsedStatements) {
				if (model.size() != parsedModel.size()) {
					if (model.size() < 1000) {
						boolean originalIsSubset = Models.isSubset(model, parsedModel);
						boolean parsedIsSubset = Models.isSubset(parsedModel, model);
						logger.debug("originalIsSubset=" + originalIsSubset);
						logger.debug("parsedIsSubset=" + parsedIsSubset);

//						System.out.println("Written statements=>");
//						IOUtils.writeLines(IOUtils.readLines(new FileInputStream(testFile)), "\n", System.out);
//						System.out.println("Parsed statements=>");
//						Rio.write(parsedModel, System.out, RDFFormat.NQUADS);
					}
				}
				assertEquals(
						"Unexpected number of statements, expected " + model.size() + " found " + parsedModel.size(),
						model.size(), parsedModel.size());

				if (rdfParser.getRDFFormat().supportsNamespaces()) {
					assertTrue("Expected at least 5 namespaces, found " + parsedModel.getNamespaces().size(),
							parsedModel.getNamespaces().size() >= 5);
					assertEquals(exNs, parsedModel.getNamespace("ex").get().getName());
				}
			}
		}
	}