Search in sources :

Example 91 with Statement

use of org.apache.jena.rdf.model.Statement in project legato by DOREMUS-ANR.

the class SupportMergedKeys method fileParsing.

private static HashMap<String, HashSet<String>> fileParsing(String file) throws IOException {
    HashMap<String, HashSet<String>> instancesPerProperty = new HashMap<>();
    Model model = ModelManager.loadModel(file);
    StmtIterator iter = model.listStatements();
    while (iter.hasNext()) {
        Statement stmt = iter.nextStatement();
        Resource subject = stmt.getSubject();
        Property prop = stmt.getPredicate();
        String instance = subject.toString();
        String property = prop.toString();
        allInstances.add(instance);
        if (instancesPerProperty.containsKey(property)) {
            instancesPerProperty.get(property).add(instance);
        } else {
            HashSet<String> instances = new HashSet<>();
            instances.add(instance);
            instancesPerProperty.put(property, instances);
        }
    }
    return instancesPerProperty;
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) HashMap(java.util.HashMap) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property) HashSet(java.util.HashSet)

Example 92 with Statement

use of org.apache.jena.rdf.model.Statement in project legato by DOREMUS-ANR.

the class KeysClassifier method getCommonProperties.

public static List<Property> getCommonProperties(Model srcModel, Model tgtModel) {
    /**
     **
     * Get All Predicates of the source model
     ***
     */
    List<Property> propSRC = new ArrayList<Property>();
    StmtIterator iterSRCModel = srcModel.listStatements();
    while (iterSRCModel.hasNext()) {
        Statement stmt = iterSRCModel.nextStatement();
        Property prop = stmt.getPredicate();
        if (!(propSRC.contains(prop))) {
            propSRC.add(prop);
        }
    }
    /**
     **
     * Get All Common Predicates for both models
     ***
     */
    List<Property> commonProperties = new ArrayList<Property>();
    StmtIterator iterTGTModel = tgtModel.listStatements();
    while (iterTGTModel.hasNext()) {
        Statement stmt = iterTGTModel.nextStatement();
        Property prop = stmt.getPredicate();
        if (!(commonProperties.contains(prop)) && (propSRC.contains(prop))) {
            // If "prop" is a common property for both datasets
            commonProperties.add(prop);
        }
    }
    return commonProperties;
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) Statement(org.apache.jena.rdf.model.Statement) ArrayList(java.util.ArrayList) Property(org.apache.jena.rdf.model.Property)

Example 93 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class ShaclTests method parseIncludes.

private static void parseIncludes(Resource manifest, List<String> manifests, List<ShaclTestItem> testCases) {
    StmtIterator includeStmts = manifest.listProperties(MF.include);
    for (; includeStmts.hasNext(); ) {
        Statement s = includeStmts.nextStatement();
        if (!(s.getObject() instanceof Resource)) {
            Log.warn(ShaclTestItem.class, "Include: not a Resource" + s);
            continue;
        }
        Resource r = s.getResource();
        parseOneIncludesList(r, manifests, testCases);
    }
    includeStmts.close();
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) Statement(org.apache.jena.rdf.model.Statement) Resource(org.apache.jena.rdf.model.Resource)

Example 94 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class SecuredResourceTest method testListProperties.

private void testListProperties(Supplier<StmtIterator> supplier, boolean expected, String txt) {
    try {
        StmtIterator iter = supplier.get();
        if (!shouldRead()) {
            Assert.fail("Should have thrown ReadDeniedException Exception");
        }
        if (securityEvaluator.evaluate(Action.Read)) {
            assertEquals(expected, iter.hasNext());
            if (expected) {
                Statement stmt = iter.next();
                assertEquals(txt, stmt.getObject().asLiteral().getString());
            }
        } else {
            assertFalse(iter.hasNext());
        }
    } catch (final ReadDeniedException e) {
        if (shouldRead()) {
            Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    }
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) Statement(org.apache.jena.rdf.model.Statement) ReadDeniedException(org.apache.jena.shared.ReadDeniedException)

Example 95 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class TestConcurrentAccess method mrswGraph3.

@Test(expected = ConcurrentModificationException.class)
public void mrswGraph3() {
    Model m = create().getDefaultModel();
    Resource r = m.createResource("x");
    ExtendedIterator<Statement> iter1 = m.listStatements(r, null, (RDFNode) null);
    assertNotNull(iter1.next());
    Triple t = SSE.parseTriple("(<y> <p> 99)");
    m.getGraph().delete(t);
    // Bad
    iter1.hasNext();
}
Also used : Triple(org.apache.jena.graph.Triple) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Test(org.junit.Test)

Aggregations

Statement (org.apache.jena.rdf.model.Statement)141 Model (org.apache.jena.rdf.model.Model)56 Resource (org.apache.jena.rdf.model.Resource)46 StmtIterator (org.apache.jena.rdf.model.StmtIterator)46 Test (org.junit.Test)39 RDFNode (org.apache.jena.rdf.model.RDFNode)29 Dataset (org.apache.jena.query.Dataset)28 ArrayList (java.util.ArrayList)25 Property (org.apache.jena.rdf.model.Property)18 ReifiedStatement (org.apache.jena.rdf.model.ReifiedStatement)17 Triple (org.apache.jena.graph.Triple)16 WonMessageValidator (won.protocol.validation.WonMessageValidator)14 TextIndexException (org.apache.jena.query.text.TextIndexException)12 Ignore (org.junit.Ignore)10 ReadDeniedException (org.apache.jena.shared.ReadDeniedException)8 Iterator (java.util.Iterator)7 SecuredReifiedStatement (org.apache.jena.permissions.model.SecuredReifiedStatement)7 SecuredStatement (org.apache.jena.permissions.model.SecuredStatement)7 Literal (org.apache.jena.rdf.model.Literal)7 SecuredPrefixMappingTest (org.apache.jena.permissions.graph.SecuredPrefixMappingTest)6