Search in sources :

Example 51 with Property

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

the class ModelManager method getFilteredTriples.

/**
 ******
 * Filter triples from an RDF model with specific properties
 *******
 */
public static Model getFilteredTriples(Model model, List<Property> listProperties) {
    Model newModel = ModelFactory.createDefaultModel();
    StmtIterator iter = model.listStatements();
    while (iter.hasNext()) {
        Statement stmt = iter.nextStatement();
        Property property = stmt.getPredicate();
        if (listProperties.contains(property)) {
            newModel.add(stmt);
        }
    }
    return model;
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) Statement(org.apache.jena.rdf.model.Statement) OntModel(org.apache.jena.ontology.OntModel) Model(org.apache.jena.rdf.model.Model) Property(org.apache.jena.rdf.model.Property)

Example 52 with Property

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

the class Prop method toString.

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append(name + " = [");
    Iterator iter = path.iterator();
    while (iter.hasNext()) {
        Property prop = (Property) iter.next();
        sb.append(prop.toString() + ", ");
    }
    sb.deleteCharAt(sb.length() - 2);
    sb.append("]");
    return sb.toString();
}
Also used : Iterator(java.util.Iterator) Property(org.apache.jena.rdf.model.Property)

Example 53 with Property

use of org.apache.jena.rdf.model.Property 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 54 with Property

use of org.apache.jena.rdf.model.Property 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 55 with Property

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

the class SecuredPropertyTest method setup.

@Override
@Before
public void setup() {
    super.setup();
    final Property p = ResourceFactory.createProperty("http://example.com/testProperty");
    setSecuredRDFNode(SecuredPropertyImpl.getInstance(securedModel, p), p);
    baseModel.add(p, SecuredRDFNodeTest.p, SecuredRDFNodeTest.o);
    baseModel.add(p, SecuredRDFNodeTest.p2, "yeehaw");
    baseModel.add(p, SecuredRDFNodeTest.p2, "yeehaw yall", "us");
    baseModel.add(p, SecuredRDFNodeTest.p2, "whohoo", "uk");
}
Also used : Property(org.apache.jena.rdf.model.Property) Before(org.junit.Before)

Aggregations

Property (org.apache.jena.rdf.model.Property)90 Resource (org.apache.jena.rdf.model.Resource)59 Model (org.apache.jena.rdf.model.Model)46 RDFNode (org.apache.jena.rdf.model.RDFNode)19 Test (org.junit.Test)18 Statement (org.apache.jena.rdf.model.Statement)17 ArrayList (java.util.ArrayList)14 StmtIterator (org.apache.jena.rdf.model.StmtIterator)14 Literal (org.apache.jena.rdf.model.Literal)11 Iterator (java.util.Iterator)6 Node (org.apache.jena.graph.Node)6 Triple (org.apache.jena.graph.Triple)6 QueryExecution (org.apache.jena.query.QueryExecution)6 OntModel (org.apache.jena.ontology.OntModel)5 Dataset (org.apache.jena.query.Dataset)5 Query (org.apache.jena.query.Query)4 InfModel (org.apache.jena.rdf.model.InfModel)4 Store (org.apache.jena.sdb.Store)4 IOException (java.io.IOException)3 LEGATO (legato.LEGATO)3