Search in sources :

Example 86 with Property

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

the class ExTDB6 method main.

public static void main(String[] args) throws Exception {
    // / turn off the "No BGP optimizer warning"
    TDB.setOptimizerWarningFlag(false);
    final String DATASET_DIR_NAME = "data0";
    final Dataset data0 = TDBFactory.createDataset(DATASET_DIR_NAME);
    // show the currently registered names
    for (Iterator<String> it = data0.listNames(); it.hasNext(); ) {
        out.println("NAME=" + it.next());
    }
    out.println("getting named model...");
    // / this is the OWL portion
    final Model model = data0.getNamedModel(MY_NS);
    out.println("Model := " + model);
    out.println("getting graph...");
    // / this is the DATA in that MODEL
    final Graph graph = model.getGraph();
    out.println("Graph := " + graph);
    if (graph.isEmpty()) {
        final Resource product1 = model.createResource(MY_NS + "product/1");
        final Property hasName = model.createProperty(MY_NS, "#hasName");
        final Statement stmt = model.createStatement(product1, hasName, model.createLiteral("Beach Ball", "en"));
        out.println("Statement = " + stmt);
        model.add(stmt);
        // just for fun
        out.println("Triple := " + stmt.asTriple().toString());
    } else {
        out.println("Graph is not Empty; it has " + graph.size() + " Statements");
        long t0, t1;
        t0 = System.currentTimeMillis();
        final Query q = QueryFactory.create("PREFIX exns: <" + MY_NS + "#>\n" + "PREFIX exprod: <" + MY_NS + "product/>\n" + " SELECT * " + // +" WHERE { exprod:1 exns:hasName ?name }"
        " WHERE { ?res ?pred ?obj }");
        out.println("Query := " + q);
        t1 = System.currentTimeMillis();
        out.println("QueryFactory.TIME=" + (t1 - t0));
        t0 = System.currentTimeMillis();
        try (QueryExecution qExec = QueryExecutionFactory.create(q, model)) {
            t1 = System.currentTimeMillis();
            out.println("QueryExecutionFactory.TIME=" + (t1 - t0));
            t0 = System.currentTimeMillis();
            ResultSet rs = qExec.execSelect();
            t1 = System.currentTimeMillis();
            out.println("executeSelect.TIME=" + (t1 - t0));
            while (rs.hasNext()) {
                QuerySolution sol = rs.next();
                out.println("Solution := " + sol);
                for (Iterator<String> names = sol.varNames(); names.hasNext(); ) {
                    final String name = names.next();
                    out.println("\t" + name + " := " + sol.get(name));
                }
            }
        }
    }
    out.println("closing graph");
    graph.close();
    out.println("closing model");
    model.close();
    // out.println("closing DataSetGraph");
    // dsg.close();
    out.println("closing DataSet");
    data0.close();
}
Also used : Statement(org.apache.jena.rdf.model.Statement) Resource(org.apache.jena.rdf.model.Resource) Graph(org.apache.jena.graph.Graph) Model(org.apache.jena.rdf.model.Model) Property(org.apache.jena.rdf.model.Property)

Example 87 with Property

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

the class SynchroSparql method run.

@Override
public void run() {
    System.out.println("dans le run saprtql");
    String url = sparqlStruct.getAdresseServeur().replaceAll("http", "jdbc:virtuoso").trim() + ":1111";
    VirtGraph graph = new VirtGraph(sparqlStruct.getGraph(), url, sparqlStruct.getNom_d_utilisateur(), sparqlStruct.getMot_de_passe());
    String str = "CLEAR GRAPH <" + sparqlStruct.getGraph() + ">";
    VirtuosoUpdateRequest vur = VirtuosoUpdateFactory.create(str, graph);
    vur.exec();
    Model m = ModelFactory.createDefaultModel();
    DownloadBean db = new DownloadBean();
    db.setConnect(conn);
    StreamedContent file = db.thesoToFile(sparqlStruct.getThesaurus(), liste_lang, liste_group, 0);
    try {
        m.read(file.getStream(), null);
    } catch (Exception e) {
    // graph.close();
    }
    StmtIterator iter = m.listStatements();
    while (iter.hasNext()) {
        Statement stmt = iter.nextStatement();
        Resource subject = stmt.getSubject();
        Property predicate = stmt.getPredicate();
        RDFNode object = stmt.getObject();
        Triple tri = new Triple(subject.asNode(), predicate.asNode(), object.asNode());
        graph.add(tri);
    }
    graph.close();
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) VirtuosoUpdateRequest(virtuoso.jena.driver.VirtuosoUpdateRequest) DownloadBean(mom.trd.opentheso.SelectedBeans.DownloadBean) Statement(org.apache.jena.rdf.model.Statement) Resource(org.apache.jena.rdf.model.Resource) Triple(org.apache.jena.graph.Triple) VirtGraph(virtuoso.jena.driver.VirtGraph) Model(org.apache.jena.rdf.model.Model) StreamedContent(org.primefaces.model.StreamedContent) Property(org.apache.jena.rdf.model.Property) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 88 with Property

use of org.apache.jena.rdf.model.Property in project webofneeds by researchstudio-sat.

the class ConnectFromNodeReviewSocketImpl method process.

@Override
public void process(final Exchange exchange) {
    Message message = exchange.getIn();
    WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
    Optional<Connection> con = connectionRepository.findOneBySocketURIAndTargetSocketURI(wonMessage.getRecipientSocketURIRequired(), wonMessage.getSenderSocketURIRequired());
    try {
        Map<Property, String> reviewData = WonRdfUtils.MessageUtils.getReviewContent(wonMessage);
        if (reviewData != null) {
            addReviewToAtom(reviewData, con.get().getConnectionURI());
        } else {
            logger.debug("No review data found in message: {}", wonMessage);
        }
    } catch (IllegalArgumentException e) {
        logger.debug("{}: for {}", e, wonMessage);
    }
}
Also used : Message(org.apache.camel.Message) WonMessage(won.protocol.message.WonMessage) WonMessage(won.protocol.message.WonMessage) Connection(won.protocol.model.Connection) Property(org.apache.jena.rdf.model.Property)

Example 89 with Property

use of org.apache.jena.rdf.model.Property in project webofneeds by researchstudio-sat.

the class JenaBnodeInDatasetTest method assertSameSubjBnode.

private void assertSameSubjBnode(Dataset dataset, final String ns, final String g1, final String g2, final String pred1, final String pred2) {
    Model model1 = dataset.getNamedModel(ns + g1);
    Model model2 = dataset.getNamedModel(ns + g2);
    Property prop1 = model1.createProperty(ns, pred1);
    ResIterator iter1 = model1.listResourcesWithProperty(prop1, null);
    Property prop2 = model2.createProperty(ns, pred2);
    ResIterator iter2 = model2.listResourcesWithProperty(prop2, null);
    Resource r1 = iter1.next();
    Resource r2 = iter2.next();
    Assert.assertTrue(r1 != null && r1.equals(r2));
}
Also used : ResIterator(org.apache.jena.rdf.model.ResIterator) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property)

Example 90 with Property

use of org.apache.jena.rdf.model.Property in project webofneeds by researchstudio-sat.

the class DefaultAtomModelWrapper method getLocationCoordinate.

/**
 * Tries to retrieve the coordinates of the location stored in the contentNode
 * within the given locationProperty
 *
 * @param contentNode contentNode in which the locationProperty is searched for
 * @param locationProperty e.g SCHEMA.LOCATION or SCHEMA.JOBLOCATION is not
 * present in the contentNode
 * @return Coordinate if found otherwise null
 */
private Coordinate getLocationCoordinate(Resource contentNode, Property locationProperty) {
    Model atomModel = getAtomModel();
    Property geoProperty = atomModel.createProperty("http://schema.org/", "geo");
    Property longitudeProperty = atomModel.createProperty("http://schema.org/", "longitude");
    Property latitudeProperty = atomModel.createProperty("http://schema.org/", "latitude");
    RDFNode locationNode = RdfUtils.findOnePropertyFromResource(atomModel, contentNode, locationProperty);
    RDFNode geoNode = (locationNode != null && locationNode.isResource()) ? RdfUtils.findOnePropertyFromResource(atomModel, locationNode.asResource(), geoProperty) : null;
    RDFNode lat = (geoNode != null && geoNode.isResource()) ? RdfUtils.findOnePropertyFromResource(atomModel, geoNode.asResource(), latitudeProperty) : null;
    RDFNode lon = (geoNode != null && geoNode.isResource()) ? RdfUtils.findOnePropertyFromResource(atomModel, geoNode.asResource(), longitudeProperty) : null;
    if (lat == null || lon == null) {
        return null;
    }
    Float latitude = Float.valueOf(lat.asLiteral().getString());
    Float longitude = Float.valueOf(lon.asLiteral().getString());
    return new Coordinate(latitude, longitude);
}
Also used : Coordinate(won.protocol.model.Coordinate) Model(org.apache.jena.rdf.model.Model) Property(org.apache.jena.rdf.model.Property) RDFNode(org.apache.jena.rdf.model.RDFNode)

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