use of mom.trd.opentheso.bdd.helper.nodes.NodeLang in project opentheso by miledrousset.
the class ExportRdf4jHelper method addThesaurus.
public void addThesaurus(String idThesaurus, List<NodeLang> selectedLanguages) {
nodeThesaurus = new ThesaurusHelper().getNodeThesaurus(ds, idThesaurus);
String uri = getUriFromId(nodeThesaurus.getIdThesaurus());
SKOSResource conceptScheme = new SKOSResource(uri, SKOSProperty.ConceptScheme);
idTheso = nodeThesaurus.getIdThesaurus();
String creator;
String contributor;
String title;
String language;
for (Thesaurus thesaurus : nodeThesaurus.getListThesaurusTraduction()) {
boolean isInSelectedLanguages = false;
for (NodeLang nodeLang : selectedLanguages) {
if (nodeLang.getCode().equals(thesaurus.getLanguage())) {
isInSelectedLanguages = true;
break;
}
}
if (!isInSelectedLanguages) {
break;
}
creator = thesaurus.getCreator();
contributor = thesaurus.getContributor();
title = thesaurus.getTitle();
language = thesaurus.getLanguage();
/*[...]*/
if (creator != null && !creator.equalsIgnoreCase("null")) {
conceptScheme.addCreator(creator, SKOSProperty.creator);
}
if (contributor != null && !contributor.equalsIgnoreCase("null")) {
conceptScheme.addCreator(creator, SKOSProperty.contributor);
}
if (title != null && language != null) {
conceptScheme.addLabel(title, language, SKOSProperty.prefLabel);
}
// dates
String created = thesaurus.getCreated().toString();
String modified = thesaurus.getModified().toString();
if (created != null) {
conceptScheme.addDate(created, SKOSProperty.created);
}
if (modified != null) {
conceptScheme.addDate(modified, SKOSProperty.modified);
}
}
skosXmlDocument.setConceptScheme(conceptScheme);
}
use of mom.trd.opentheso.bdd.helper.nodes.NodeLang in project opentheso by miledrousset.
the class ExportRdf4jHelper method addNoteGiven.
private void addNoteGiven(ArrayList<NodeNote> nodeNotes, SKOSResource resource, List<NodeLang> selectedLanguages) {
for (NodeNote note : nodeNotes) {
boolean isInselectedLanguages = false;
for (NodeLang nodeLang : selectedLanguages) {
if (nodeLang.getCode().equals(note.getLang())) {
isInselectedLanguages = true;
break;
}
}
if (!isInselectedLanguages) {
continue;
}
int prop;
switch(note.getNotetypecode()) {
case "scopeNote":
prop = SKOSProperty.scopeNote;
break;
case "historyNote":
prop = SKOSProperty.historyNote;
break;
case "definition":
prop = SKOSProperty.definition;
break;
case "editorialNote":
prop = SKOSProperty.editorialNote;
break;
default:
prop = SKOSProperty.note;
break;
}
resource.addDocumentation(note.getLexicalvalue(), note.getLang(), prop);
}
}
use of mom.trd.opentheso.bdd.helper.nodes.NodeLang in project opentheso by miledrousset.
the class GpsQuery method queryGps2.
public ArrayList<NodeAlignment> queryGps2(String idC, String idTheso, String lexicalValue, String lang, String requete) {
ArrayList<NodeLang> nodeLangs;
try {
lexicalValue = URLEncoder.encode(lexicalValue, "UTF-8");
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(GpsQuery.class.getName()).log(Level.SEVERE, null, ex);
}
lexicalValue = lexicalValue.replaceAll(" ", "%20");
requete = requete.replace("##lang##", lang);
requete = requete.replace("##value##", lexicalValue);
try {
// URL url = new URL("https://" + lang + ".wikipedia.org/w/api.php?action=query&list=search&srwhat=text&format=xml&srsearch=" + lexicalValue + "&srnamespace=0");
// requete = URLEncoder.encode(requete, "UTF-8");
URL url = new URL(requete);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/xml");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
String output;
String xmlRecord = "";
while ((output = br.readLine()) != null) {
xmlRecord += output;
}
byte[] bytes = xmlRecord.getBytes();
xmlRecord = new String(bytes, Charset.forName("UTF-8"));
conn.disconnect();
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xmlRecord));
org.w3c.dom.Document doc = db.parse(is);
NodeList nodes = doc.getElementsByTagName("geoname");
listeAlign = new ArrayList<>();
// iterate the employees
for (int i = 0; i < nodes.getLength(); i++) {
nodeLangs = new ArrayList<>();
org.w3c.dom.Element element = (org.w3c.dom.Element) nodes.item(i);
NodeAlignment nodeAlignment = new NodeAlignment();
NodeList nodeList = element.getElementsByTagName("name");
for (int j = 0; j < nodeList.getLength(); j++) {
nodeAlignment.setName(nodeList.item(j).getTextContent());
}
nodeList = element.getElementsByTagName("lat");
if (nodeList != null && nodeList.getLength() > 0) {
for (int j = 0; j < nodeList.getLength(); j++) {
nodeAlignment.setLat(Double.parseDouble(nodeList.item(j).getTextContent()));
}
}
nodeList = element.getElementsByTagName("lng");
if (nodeList != null && nodeList.getLength() > 0) {
for (int j = 0; j < nodeList.getLength(); j++) {
nodeAlignment.setLng(Double.parseDouble(nodeList.item(j).getTextContent()));
}
}
nodeList = element.getElementsByTagName("geonameId");
if (nodeList != null && nodeList.getLength() > 0) {
for (int j = 0; j < nodeList.getLength(); j++) {
nodeAlignment.setIdUrl("http://www.geonames.org/" + (nodeList.item(j).getTextContent()));
}
}
nodeList = element.getElementsByTagName("countryName");
if (nodeList != null && nodeList.getLength() > 0) {
for (int j = 0; j < nodeList.getLength(); j++) {
nodeAlignment.setCountryName(nodeList.item(j).getTextContent());
}
}
nodeList = element.getElementsByTagName("toponymName");
if (nodeList != null && nodeList.getLength() > 0) {
for (int j = 0; j < nodeList.getLength(); j++) {
nodeAlignment.setToponymName(nodeList.item(j).getTextContent());
}
}
nodeList = element.getElementsByTagName("adminName1");
if (nodeList != null && nodeList.getLength() > 0) {
for (int j = 0; j < nodeList.getLength(); j++) {
nodeAlignment.setAdminName1(nodeList.item(j).getTextContent());
}
}
nodeList = element.getElementsByTagName("adminName2");
if (nodeList != null && nodeList.getLength() > 0) {
for (int j = 0; j < nodeList.getLength(); j++) {
nodeAlignment.setAdminName2(nodeList.item(j).getTextContent());
}
}
nodeList = element.getElementsByTagName("alternateName");
if (nodeList != null && nodeList.getLength() > 0) {
for (int j = 0; j < nodeList.getLength(); j++) {
NodeLang nodeLang = new NodeLang();
// nodeAlignment.setToponymName(p.item(j).getTextContent());
ArrayList<String> langueFound = new ArrayList<>();
org.w3c.dom.Element el = (org.w3c.dom.Element) nodeList.item(j);
if (el.hasAttribute("lang")) {
nodeLang.setCode(el.getAttribute("lang"));
nodeLang.setValue(nodeList.item(j).getTextContent());
}
nodeLangs.add(nodeLang);
}
nodeAlignment.setAlltraductions(nodeLangs);
}
listeAlign.add(nodeAlignment);
}
} catch (ParserConfigurationException | SAXException | IOException e) {
}
} catch (MalformedURLException e) {
} catch (IOException e) {
}
return listeAlign;
}
use of mom.trd.opentheso.bdd.helper.nodes.NodeLang in project opentheso by miledrousset.
the class ExportTabulateHelper method writeConcepts.
private boolean writeConcepts() {
ArrayList<NodeConceptExport> nodeConceptExports = thesaurusDatas.getNodeConceptExports();
boolean first = true;
ArrayList<NodeNote> nodeNoteDefinition = new ArrayList<>();
ArrayList<NodeNote> nodeNoteScope = new ArrayList<>();
ArrayList<NodeNote> nodeNoteHistory = new ArrayList<>();
ArrayList<NodeNote> nodeNoteEditorial = new ArrayList<>();
ArrayList<String> listLangues = new ArrayList<>();
for (NodeLang selectedLanguage : selectedLanguages) {
listLangues.add(selectedLanguage.getCode());
}
for (NodeConceptExport nodeConceptExport : nodeConceptExports) {
nodeNoteDefinition.clear();
nodeNoteScope.clear();
nodeNoteHistory.clear();
nodeNoteEditorial.clear();
// id
tabulateBuff.append(nodeConceptExport.getConcept().getIdConcept());
tabulateBuff.append(";");
// idArk
if (nodeConceptExport.getConcept().getIdArk() == null) {
tabulateBuff.append("");
} else {
tabulateBuff.append(nodeConceptExport.getConcept().getIdArk());
}
tabulateBuff.append(";");
// type
if (nodeConceptExport.getConcept().isTopConcept()) {
tabulateBuff.append("TT");
} else {
tabulateBuff.append("DE");
}
tabulateBuff.append(";");
// preflabel
for (NodeTermTraduction nodeTermTraduction : nodeConceptExport.getNodeTermTraductions()) {
if (listLangues.contains(nodeTermTraduction.getLang())) {
if (!first) {
tabulateBuff.append("##");
}
tabulateBuff.append(nodeTermTraduction.getLexicalValue());
tabulateBuff.append("::");
tabulateBuff.append(nodeTermTraduction.getLang());
first = false;
}
}
tabulateBuff.append(";");
// altLabel
first = true;
for (NodeEM nodeEM : nodeConceptExport.getNodeEM()) {
if (listLangues.contains(nodeEM.getLang())) {
if (!first) {
tabulateBuff.append("##");
}
tabulateBuff.append(nodeEM.getLexical_value());
tabulateBuff.append("::");
tabulateBuff.append(nodeEM.getLang());
first = false;
}
}
tabulateBuff.append(";");
// inScheme
first = true;
for (NodeUri nodeUri : nodeConceptExport.getNodeListIdsOfConceptGroup()) {
if (!first) {
tabulateBuff.append("##");
}
tabulateBuff.append(nodeUri.getIdConcept());
first = false;
}
tabulateBuff.append(";");
// broader
first = true;
for (NodeHieraRelation node : nodeConceptExport.getNodeListOfBT()) {
if (!first) {
tabulateBuff.append("##");
}
tabulateBuff.append(node.getUri().getIdConcept());
first = false;
}
tabulateBuff.append(";");
// narrower
first = true;
for (NodeHieraRelation node : nodeConceptExport.getNodeListOfNT()) {
if (!first) {
tabulateBuff.append("##");
}
tabulateBuff.append(node.getUri().getIdConcept());
first = false;
}
tabulateBuff.append(";");
// related
first = true;
for (NodeHieraRelation nodeUri : nodeConceptExport.getNodeListIdsOfRT()) {
if (!first) {
tabulateBuff.append("##");
}
tabulateBuff.append(nodeUri.getUri().getIdConcept());
first = false;
}
tabulateBuff.append(";");
// alignment
first = true;
for (NodeAlignment nodeAlignment : nodeConceptExport.getNodeAlignmentsList()) {
if (!first) {
tabulateBuff.append("##");
}
if (nodeAlignment.getAlignement_id_type() == 1) {
tabulateBuff.append("exactMatch::");
tabulateBuff.append(nodeAlignment.getUri_target());
}
if (nodeAlignment.getAlignement_id_type() == 2) {
tabulateBuff.append("closeMatch::");
tabulateBuff.append(nodeAlignment.getUri_target());
}
first = false;
}
tabulateBuff.append(";");
// types : definition; editorialNote; historyNote ; scopeNote
for (NodeNote nodeNote : nodeConceptExport.getNodeNoteConcept()) {
nodeNote.setLexicalvalue(nodeNote.getLexicalvalue().replace('\r', ' '));
nodeNote.setLexicalvalue(nodeNote.getLexicalvalue().replace('\n', ' '));
if (nodeNote.getNotetypecode().equalsIgnoreCase("definition")) {
nodeNoteDefinition.add(nodeNote);
}
if (nodeNote.getNotetypecode().equalsIgnoreCase("editorialNote")) {
nodeNoteEditorial.add(nodeNote);
}
if (nodeNote.getNotetypecode().equalsIgnoreCase("historyNote")) {
nodeNoteHistory.add(nodeNote);
}
if (nodeNote.getNotetypecode().equalsIgnoreCase("scopeNote")) {
nodeNoteScope.add(nodeNote);
}
}
// types : definition; editorialNote; historyNote ; scopeNote
for (NodeNote nodeNote : nodeConceptExport.getNodeNoteTerm()) {
nodeNote.setLexicalvalue(nodeNote.getLexicalvalue().replace('\r', ' '));
nodeNote.setLexicalvalue(nodeNote.getLexicalvalue().replace('\n', ' '));
if (nodeNote.getNotetypecode().equalsIgnoreCase("definition")) {
nodeNoteDefinition.add(nodeNote);
}
if (nodeNote.getNotetypecode().equalsIgnoreCase("editorialNote")) {
nodeNoteEditorial.add(nodeNote);
}
if (nodeNote.getNotetypecode().equalsIgnoreCase("historyNote")) {
nodeNoteHistory.add(nodeNote);
}
if (nodeNote.getNotetypecode().equalsIgnoreCase("scopeNote")) {
nodeNoteScope.add(nodeNote);
}
}
// definition
first = true;
for (NodeNote nodeNote : nodeNoteDefinition) {
if (listLangues.contains(nodeNote.getLang())) {
if (!first) {
tabulateBuff.append("##");
}
tabulateBuff.append(nodeNote.getLexicalvalue());
tabulateBuff.append("::");
tabulateBuff.append(nodeNote.getLang());
first = false;
}
}
tabulateBuff.append(";");
// scopeNote
first = true;
for (NodeNote nodeNote : nodeNoteScope) {
if (listLangues.contains(nodeNote.getLang())) {
if (!first) {
tabulateBuff.append("##");
}
tabulateBuff.append(nodeNote.getLexicalvalue());
tabulateBuff.append("::");
tabulateBuff.append(nodeNote.getLang());
first = false;
}
}
tabulateBuff.append(";");
// historyNote
first = true;
for (NodeNote nodeNote : nodeNoteHistory) {
if (listLangues.contains(nodeNote.getLang())) {
if (!first) {
tabulateBuff.append("##");
}
tabulateBuff.append(nodeNote.getLexicalvalue());
tabulateBuff.append("::");
tabulateBuff.append(nodeNote.getLang());
first = false;
}
}
tabulateBuff.append(";");
// editorialNote
first = true;
for (NodeNote nodeNote : nodeNoteEditorial) {
if (listLangues.contains(nodeNote.getLang())) {
if (!first) {
tabulateBuff.append("##");
}
tabulateBuff.append(nodeNote.getLexicalvalue());
tabulateBuff.append("::");
tabulateBuff.append(nodeNote.getLang());
first = false;
}
}
tabulateBuff.append(";");
// dates
tabulateBuff.append(nodeConceptExport.getConcept().getCreated());
tabulateBuff.append(";");
tabulateBuff.append(nodeConceptExport.getConcept().getModified());
tabulateBuff.append("\n");
first = true;
}
return true;
}
use of mom.trd.opentheso.bdd.helper.nodes.NodeLang in project opentheso by miledrousset.
the class WriteFileSKOS 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
* @param selectedLanguages
*
* @return true ou false
*/
public boolean writeDescriptor(NodeConceptExport nodeConceptExport, List<NodeLang> selectedLanguages) {
/*
// test pour savoir si le concept n'a pas de PrefLabel dans cette langue, il sera ignoré
boolean havePrefLabel = false;
if(selectedLanguages != null) {
for (int i = 0; i < nodeConceptExport.getNodeTermTraductions().size(); i++) {
for (NodeLang selectedLanguage : selectedLanguages) {
if (nodeConceptExport.getNodeTermTraductions().get(i).getLang().equalsIgnoreCase(
selectedLanguage.getCode())) {
havePrefLabel = true;
}
}
}
if(!havePrefLabel) return true; // on ignore le concept
}*/
SKOSResource concept = new SKOSResource(getUri(nodeConceptExport));
if (nodeConceptExport == null) {
return true;
}
if (nodeConceptExport.getNodeTermTraductions() == null) {
return true;
}
for (int i = 0; i < nodeConceptExport.getNodeTermTraductions().size(); i++) {
if (selectedLanguages != null) {
// if(nodeConceptExport.getNodeTermTraductions().get(i).getLang().equalsIgnoreCase("fr"))
for (NodeLang selectedLanguage : selectedLanguages) {
if (nodeConceptExport.getNodeTermTraductions().get(i).getLang().equalsIgnoreCase(selectedLanguage.getCode())) {
concept.addLabel(nodeConceptExport.getNodeTermTraductions().get(i).getLexicalValue(), nodeConceptExport.getNodeTermTraductions().get(i).getLang(), SKOSProperty.prefLabel);
}
}
} else {
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().getNotation().isEmpty()) {
concept.addNotation(nodeConceptExport.getConcept().getNotation(), SKOSProperty.notation);
}
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), 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.getNodeListIdsOfBT().get(i), SKOSProperty.broader);
concept.addRelation(getRelationUri(nodeConceptExport.getNodeListOfBT().get(i).getUri(), nodeConceptExport.getConcept().getIdThesaurus()), SKOSProperty.broader);
}
for (int i = 0; i < nodeConceptExport.getNodeListOfNT().size(); i++) {
// concept.addRelation(URI + "/concept#" + nodeConceptExport.getNodeListIdsOfNT().get(i), SKOSProperty.narrower);
concept.addRelation(getRelationUri(nodeConceptExport.getNodeListOfNT().get(i).getUri(), nodeConceptExport.getConcept().getIdThesaurus()), SKOSProperty.narrower);
}
for (int i = 0; i < nodeConceptExport.getNodeListIdsOfRT().size(); i++) {
// concept.addRelation(URI + "/concept#" + nodeConceptExport.getNodeListIdsOfRT().get(i), SKOSProperty.related);
concept.addRelation(getRelationUri(nodeConceptExport.getNodeListIdsOfRT().get(i).getUri(), 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(prepareUriTohtml(alignment.getUri_target()), SKOSMapping.exactMatch);
}
// alignement closeMatch
if (alignment.getAlignement_id_type() == 2) {
concept.addMapping(prepareUriTohtml(alignment.getUri_target()), SKOSMapping.closeMatch);
}
// alignement broadMatch
if (alignment.getAlignement_id_type() == 3) {
concept.addMapping(prepareUriTohtml(alignment.getUri_target()), SKOSMapping.broadMatch);
}
// alignement relatedMatch
if (alignment.getAlignement_id_type() == 4) {
concept.addMapping(prepareUriTohtml(alignment.getUri_target()), SKOSMapping.relatedMatch);
}
// alignement narrowMatch
if (alignment.getAlignement_id_type() == 5) {
concept.addMapping(prepareUriTohtml(alignment.getUri_target()), SKOSMapping.narrowMatch);
}
}
for (NodeNote nodeNote : nodeConceptExport.getNodeNoteTerm()) {
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);
}
}
for (NodeNote nodeNote : nodeConceptExport.getNodeNoteConcept()) {
if (nodeNote.getNotetypecode().equalsIgnoreCase("note")) {
concept.addDocumentation(nodeNote.getLexicalvalue(), nodeNote.getLang(), SKOSProperty.note);
}
if (nodeNote.getNotetypecode().equalsIgnoreCase("scopeNote")) {
concept.addDocumentation(nodeNote.getLexicalvalue(), nodeNote.getLang(), SKOSProperty.scopeNote);
}
}
if (nodeConceptExport.getNodeGps() != null) {
concept.addSkosGps(nodeConceptExport.getNodeGps().getLatitude(), SKOSProperty.latitude);
concept.addSkosGps(nodeConceptExport.getNodeGps().getLongitude(), SKOSProperty.longitude);
}
skosBuff.append(" ").append(concept.toString());
return true;
}
Aggregations