Search in sources :

Example 21 with NodeAlignment

use of mom.trd.opentheso.bdd.helper.nodes.NodeAlignment in project opentheso by miledrousset.

the class AlignmentQuery method queryAgrovoc.

/**
 * Cette fonction permet de récupérer les alignements présents sur Agrovoc
 * pour un concept passé en paramètre
 *
 * @param idC
 * @param idTheso
 * @param lexicalValue
 * @param lang
 * @return
 */
private ArrayList<NodeAlignment> queryAgrovoc(String idC, String idTheso, String lexicalValue, String lang, String source) {
    listeAlign = new ArrayList<>();
    lexicalValue = String.valueOf(lexicalValue.charAt(0)).toUpperCase() + lexicalValue.substring(1);
    String sparqlQueryString1 = "PREFIX skos: <http://www.w3.org/2004/02/skos/core#> " + "SELECT * WHERE {" + "       ?uri skos:prefLabel ?pl ." + "       FILTER(regex(?pl,\"" + lexicalValue + "*\"))" + "       FILTER ( (lang(?pl)=\"" + lang + "\") )" + "       OPTIONAL { " + "       ?uri skos:scopeNote ?def ." + "       FILTER ( (lang(?def)=\"" + lang + "\") )" + "       }" + "   }";
    // System.out.println(sparqlQueryString1);
    Query query = QueryFactory.create(sparqlQueryString1);
    QueryExecution qexec = QueryExecutionFactory.sparqlService("URL A DEFINIR", query);
    ResultSet results = qexec.execSelect();
    while (results.hasNext()) {
        QuerySolution qs = results.next();
        NodeAlignment na = new NodeAlignment();
        na.setInternal_id_concept(idC);
        na.setInternal_id_thesaurus(idTheso);
        na.setConcept_target(qs.get("pl").toString());
        na.setDef_target(qs.get("def").toString());
        na.setThesaurus_target(source);
        na.setUri_target(qs.get("uri").toString());
        listeAlign.add(na);
    }
    qexec.close();
    return listeAlign;
}
Also used : NodeAlignment(mom.trd.opentheso.bdd.helper.nodes.NodeAlignment) Query(org.apache.jena.query.Query) QuerySolution(org.apache.jena.query.QuerySolution) ResultSet(org.apache.jena.query.ResultSet) QueryExecution(org.apache.jena.query.QueryExecution)

Example 22 with NodeAlignment

use of mom.trd.opentheso.bdd.helper.nodes.NodeAlignment in project opentheso by miledrousset.

the class AlignmentQuery method queryGemet.

/**
 * Cette fonction permet de récupérer les alignements présents sur Gemet
 * pour un concept passé en paramètre
 *
 * @param idC
 * @param idTheso
 * @param lexicalValue
 * @param lang
 * @return
 */
private ArrayList<NodeAlignment> queryGemet(String idC, String idTheso, String lexicalValue, String lang) {
    listeAlign = new ArrayList<>();
    if (lexicalValue.contains(" ")) {
        lexicalValue = lexicalValue.substring(0, lexicalValue.indexOf(" "));
    }
    String sparqlQueryString1 = "PREFIX skos: <http://www.w3.org/2004/02/skos/core#> " + "SELECT * WHERE {" + "       ?uri skos:prefLabel ?pl ." + "       FILTER(regex(?pl,\"" + lexicalValue + "*\"))" + "       FILTER ( (lang(?pl)=\"" + lang + "\") )" + "   }";
    /*
        
        PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

                SELECT * WHERE {
                 ?uri skos:prefLabel ?pl .
                      FILTER(regex(?pl,"Enseignement"))
                      FILTER ( (lang(?pl)="fr") )

                  }
        */
    // System.out.println(sparqlQueryString1);
    /*String endpointURL = "http://cr.eionet.europa.eu/sparql";
         SPARQLRepository crEndpoint = new SPARQLRepository(endpointURL);
         RepositoryConnection conn = null;
         try {
         crEndpoint.initialize();
         conn = crEndpoint.getConnection();
         TupleQuery q = conn.prepareTupleQuery(QueryLanguage.SPARQL, sparqlQueryString1);
         TupleQueryResult bindings = q.evaluate();
         while (bindings.hasNext()) {
         BindingSet b = bindings.next();
         NodeAlignment na = new NodeAlignment();
         na.setInternal_id_concept(idC);
         na.setInternal_id_thesaurus(idTheso);
         na.setConcept_target(b.getBinding("pl").getValue().stringValue());
         na.setDef_target(b.getBinding("def").getValue().stringValue());
         na.setThesaurus_target("Gemet");
         na.setUri_target(b.getBinding("uri").getValue().stringValue());
         listeAlign.add(na);
         }
         } catch (Exception e) {
         e.printStackTrace();
         } finally {
         try {
         conn.close();
         } catch (RepositoryException e) {
         e.printStackTrace();
         }
         }*/
    Query query = QueryFactory.create(sparqlQueryString1);
    QueryExecution qexec = QueryExecutionFactory.sparqlService("http://cr.eionet.europa.eu/sparql", query);
    ResultSet results = qexec.execSelect();
    while (results.hasNext()) {
        QuerySolution qs = results.next();
        NodeAlignment na = new NodeAlignment();
        na.setInternal_id_concept(idC);
        na.setInternal_id_thesaurus(idTheso);
        na.setConcept_target(qs.get("pl").toString());
        na.setDef_target(qs.get("def").toString());
        na.setThesaurus_target("Gemet");
        na.setUri_target(qs.get("uri").toString());
        listeAlign.add(na);
    }
    qexec.close();
    return listeAlign;
}
Also used : NodeAlignment(mom.trd.opentheso.bdd.helper.nodes.NodeAlignment) Query(org.apache.jena.query.Query) QuerySolution(org.apache.jena.query.QuerySolution) ResultSet(org.apache.jena.query.ResultSet) QueryExecution(org.apache.jena.query.QueryExecution)

Example 23 with NodeAlignment

use of mom.trd.opentheso.bdd.helper.nodes.NodeAlignment in project opentheso by miledrousset.

the class GpsQuery method getlisteAlign.

private ArrayList<NodeAlignment> getlisteAlign(String xmlrecord) {
    ArrayList<NodeAlignment> listeAlign1 = new ArrayList<>();
    // Se crea un SAXBuilder para poder parsear el archivo
    SAXBuilder builder = new SAXBuilder();
    File xmlFile = new File(xmlrecord);
    try {
        // Se crea el documento a traves del archivo
        Document document = (Document) builder.build(xmlFile);
        // Se obtiene la raiz 'tables'
        Element rootNode = document.getRootElement();
        // Se obtiene la lista de hijos de la raiz 'tables'
        List list = rootNode.getChildren("geoname");
        // Se recorre la lista de hijos de 'tables'
        for (int i = 0; i < list.size(); i++) {
            // Se obtiene el elemento 'tabla'
            Element tabla = (Element) list.get(i);
            // Se obtiene la lista de hijos del tag 'tabla'
            List lista_campos = tabla.getChildren();
            // Se recorre la lista de campos
            for (int j = 0; j < lista_campos.size(); j++) {
                // Se obtiene el elemento 'campo'
                Element campo = (Element) lista_campos.get(j);
                // Se obtienen los valores que estan entre los tags '&lt;campo&gt;&lt;/campo&gt;'
                // Se obtiene el valor que esta entre los tags '&lt;nombre&gt;&lt;/nombre&gt;'
                String nombre = campo.getChildTextTrim("name");
                // Se obtiene el valor que esta entre los tags '&lt;tipo&gt;&lt;/tipo&gt;'
                String tname = campo.getChildTextTrim("toponymName");
                // Se obtiene el valor que esta entre los tags '&lt;valor&gt;&lt;/valor&gt;'
                String lat = campo.getChildTextTrim("lat");
                String lng = campo.getChildTextTrim("lng");
                System.out.println("\t" + nombre + "\t\t" + tname + "\t\t" + lat + "\t\t" + lng);
            }
        }
    } catch (IOException io) {
        System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
        System.out.println(jdomex.getMessage());
    }
    return listeAlign1;
}
Also used : NodeAlignment(mom.trd.opentheso.bdd.helper.nodes.NodeAlignment) SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) File(java.io.File)

Example 24 with NodeAlignment

use of mom.trd.opentheso.bdd.helper.nodes.NodeAlignment in project opentheso by miledrousset.

the class WriteFileSKOS_Frantiq method writeDescriptor.

/**
 * Cette fonction permet d'exporter un Concept au format SKOS,
 * Si l'identifiant Ark existe, on l'exporte comme URI, sinon, on utilise l'adresse URI du Site par defaut.
 *
 * @param nodeConceptExport
 *
 * @return true ou false
 */
public boolean writeDescriptor(NodeConceptExport nodeConceptExport) {
    // getUri(nodeConceptExport));
    SKOSResource concept = new SKOSResource(serverAdress + "concept#" + nodeConceptExport.getConcept().getIdConcept());
    for (int i = 0; i < nodeConceptExport.getNodeTermTraductions().size(); i++) {
        concept.addLabel(nodeConceptExport.getNodeTermTraductions().get(i).getLexicalValue(), nodeConceptExport.getNodeTermTraductions().get(i).getLang(), SKOSProperty.prefLabel);
    }
    concept.addDate(nodeConceptExport.getConcept().getCreated().toString(), SKOSProperty.created);
    concept.addDate(nodeConceptExport.getConcept().getModified().toString(), SKOSProperty.modified);
    if (!nodeConceptExport.getConcept().getIdConcept().isEmpty()) {
        concept.addIdentifier(nodeConceptExport.getConcept().getIdConcept(), SKOSProperty.identifier);
    }
    for (int i = 0; i < nodeConceptExport.getNodeListIdsOfConceptGroup().size(); i++) {
        concept.addRelation(URI + "concept#" + nodeConceptExport.getNodeListIdsOfConceptGroup().get(i).getIdConcept(), SKOSProperty.inScheme);
    /*    concept.addRelation(
                    getRelationUri_inScheme(nodeConceptExport.getNodeListIdsOfConceptGroup().get(i),
                            nodeConceptExport.getConcept().getIdThesaurus()),
                    SKOSProperty.inScheme);*/
    }
    for (int i = 0; i < nodeConceptExport.getNodeListOfBT().size(); i++) {
        concept.addRelation(URI + "concept#" + nodeConceptExport.getNodeListOfBT().get(i).getUri().getIdConcept(), SKOSProperty.broader);
    /*    concept.addRelation(
                    getRelationUri(nodeConceptExport.getNodeListIdsOfBT().get(i),
                            nodeConceptExport.getConcept().getIdThesaurus()),
                    SKOSProperty.broader);
            */
    }
    for (int i = 0; i < nodeConceptExport.getNodeListOfNT().size(); i++) {
        concept.addRelation(URI + "concept#" + nodeConceptExport.getNodeListOfNT().get(i).getUri().getIdConcept(), SKOSProperty.narrower);
    /*    concept.addRelation(
                    getRelationUri(nodeConceptExport.getNodeListIdsOfNT().get(i),
                            nodeConceptExport.getConcept().getIdThesaurus()),
                    SKOSProperty.narrower);
            */
    }
    for (int i = 0; i < nodeConceptExport.getNodeListIdsOfRT().size(); i++) {
        concept.addRelation(URI + "concept#" + nodeConceptExport.getNodeListIdsOfRT().get(i).getUri().getIdConcept(), SKOSProperty.related);
    /*    concept.addRelation(
                    getRelationUri(nodeConceptExport.getNodeListIdsOfRT().get(i),
                            nodeConceptExport.getConcept().getIdThesaurus()),
                    SKOSProperty.related);
            */
    }
    for (int i = 0; i < nodeConceptExport.getNodeEM().size(); i++) {
        if (nodeConceptExport.getNodeEM().get(i).isHiden()) {
            concept.addLabel(nodeConceptExport.getNodeEM().get(i).getLexical_value(), nodeConceptExport.getNodeEM().get(i).getLang(), SKOSProperty.hiddenLabel);
        } else {
            concept.addLabel(nodeConceptExport.getNodeEM().get(i).getLexical_value(), nodeConceptExport.getNodeEM().get(i).getLang(), SKOSProperty.altLabel);
        }
    }
    for (NodeAlignment alignment : nodeConceptExport.getNodeAlignmentsList()) {
        // alignement exactMatch
        if (alignment.getAlignement_id_type() == 1) {
            concept.addMapping(alignment.getUri_target().trim(), SKOSMapping.exactMatch);
        }
        // alignement closeMatch
        if (alignment.getAlignement_id_type() == 2) {
            concept.addMapping(alignment.getUri_target().trim(), SKOSMapping.closeMatch);
        }
    }
    for (NodeNote nodeNote : nodeConceptExport.getNodeNoteTerm()) {
        if (nodeNote.getNotetypecode().equalsIgnoreCase("scopeNote")) {
            concept.addDocumentation(nodeNote.getLexicalvalue(), nodeNote.getLang(), SKOSProperty.scopeNote);
        }
        if (nodeNote.getNotetypecode().equalsIgnoreCase("historyNote")) {
            concept.addDocumentation(nodeNote.getLexicalvalue(), nodeNote.getLang(), SKOSProperty.historyNote);
        }
        if (nodeNote.getNotetypecode().equalsIgnoreCase("editorialNote")) {
            concept.addDocumentation(nodeNote.getLexicalvalue(), nodeNote.getLang(), SKOSProperty.editorialNote);
        }
        if (nodeNote.getNotetypecode().equalsIgnoreCase("definition")) {
            concept.addDocumentation(nodeNote.getLexicalvalue(), nodeNote.getLang(), SKOSProperty.definition);
        }
    }
    skosBuff.append("    ").append(concept.toString());
    return true;
}
Also used : NodeAlignment(mom.trd.opentheso.bdd.helper.nodes.NodeAlignment) SKOSResource(skos.SKOSResource) NodeNote(mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote)

Aggregations

NodeAlignment (mom.trd.opentheso.bdd.helper.nodes.NodeAlignment)24 ArrayList (java.util.ArrayList)7 AlignmentHelper (mom.trd.opentheso.bdd.helper.AlignmentHelper)7 NodeNote (mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote)7 Concept (mom.trd.opentheso.bdd.datas.Concept)5 HierarchicalRelationship (mom.trd.opentheso.bdd.datas.HierarchicalRelationship)5 NodeEM (mom.trd.opentheso.bdd.helper.nodes.NodeEM)5 Connection (java.sql.Connection)4 SQLException (java.sql.SQLException)4 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)4 TermHelper (mom.trd.opentheso.bdd.helper.TermHelper)4 NodeTerm (mom.trd.opentheso.bdd.helper.nodes.term.NodeTerm)4 NodeTermTraduction (mom.trd.opentheso.bdd.helper.nodes.term.NodeTermTraduction)4 Query (org.apache.jena.query.Query)4 QueryExecution (org.apache.jena.query.QueryExecution)4 QuerySolution (org.apache.jena.query.QuerySolution)4 ResultSet (org.apache.jena.query.ResultSet)4 HttpURLConnection (java.net.HttpURLConnection)3 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3