use of org.semanticweb.skos.SKOSConceptScheme in project opentheso by miledrousset.
the class ImportSkosHelper method addThesaurus.
/**
* Fonction qui permet d'importer les informations d'un thésaurus
* @return
*/
public boolean addThesaurus() {
ThesaurusHelper thesaurusHelper = new ThesaurusHelper();
idGroupDefault = getNewId();
for (SKOSConceptScheme scheme : dataSet.getSKOSConceptSchemes()) {
// récupération du nom de thésaurus
thesaurus.setTitle(getIdFromUri(scheme.getURI().toString()));
conceptsCount = dataSet.getSKOSConcepts().size();
for (SKOSAnnotation anno : scheme.getSKOSAnnotations(dataSet)) {
if (anno.isAnnotationByConstant()) {
if (anno.getAnnotationValueAsConstant().isTyped()) {
SKOSTypedLiteral con = anno.getAnnotationValueAsConstant().getAsSKOSTypedLiteral();
// System.err.print(con.getLiteral() + " Type: " + con.getDataType().getURI());
} else {
SKOSUntypedLiteral con = anno.getAnnotationValueAsConstant().getAsSKOSUntypedLiteral();
if (anno.getURI().toString().contains("title")) {
DcElement dcElement = new DcElement();
dcElement.setName("title");
dcElement.setValue(con.getLiteral());
if (con.hasLang()) {
dcElement.setLanguage(con.getLang());
} else
dcElement.setLanguage(langueSource);
thesaurus.addDcElement(dcElement);
} else {
DcElement dcElement = new DcElement();
dcElement.setName("title");
dcElement.setValue(con.getLiteral());
if (con.hasLang()) {
dcElement.setLanguage(con.getLang());
} else
dcElement.setLanguage(langueSource);
thesaurus.addDcElement(dcElement);
}
}
// * created or date;
// if(anno.getURI().getPath().contains("date") ){
// getThesaurusAnnotation(anno);
// }
// // * modified;
// if(anno.getURI().getPath().contains("modified") ){
// getThesaurusAnnotation(anno);
// }
// * @param coverage
// * @param creator
// * @param description
// * @param format
// * @param id_langue
// * @param publisher
// * @param relation
// * @param rights
// * @param source
// * @param subject
// * @param title
// * @param type
} else // la liste des TopConcept
{
idTopConcept.add(getIdFromUri(anno.getAnnotationValue().getURI().toString()));
// System.err.println(anno.getAnnotationValue().getURI().toString());
}
}
if (!addThesaurusToBdd(thesaurusHelper)) {
return false;
}
if (thesaurus.getDcElement().isEmpty()) {
if (thesaurus.getTitle().isEmpty()) {
thesaurus.setTitle("theso_" + thesaurus.getId_thesaurus());
} else {
thesaurus.setTitle(thesaurus.getTitle());
}
thesaurus.setLanguage(langueSource);
thesaurusHelper.addThesaurusTraduction(ds, thesaurus);
} else {
for (DcElement dcElement : thesaurus.getDcElement()) {
thesaurus.setTitle(dcElement.getValue());
thesaurus.setLanguage(dcElement.getLanguage());
thesaurusHelper.addThesaurusTraduction(ds, thesaurus);
}
}
return true;
}
return false;
}
use of org.semanticweb.skos.SKOSConceptScheme in project opentheso by miledrousset.
the class ImportSkosHelper method readFile.
/**
* Cette fonction a été modifié pour pouvoir lire un fichier SKOS en passant par un
* InputStream, l'API standard SKOSAPI n'a pas de constructeur adapté
* cette fonction permet de lire tout type de fichier SKOS-OWL en s'appuyant
* sur l'api (OWLAPI-SKOSAPI)
*
* @param streamFilename
* @param fileName
* @return
* @throws OWLOntologyCreationException
* @throws SKOSCreationException
*/
public boolean readFile(InputStream streamFilename, String fileName) throws OWLOntologyCreationException, SKOSCreationException {
try {
sKOSManager = new SKOSManager();
onto = ontologieManager.loadOntologyFromOntologyDocument(streamFilename);
SKOSDatasetImpl voc = new SKOSDatasetImpl(sKOSManager, onto);
if (voc.getURI() != null) {
String theso = "";
for (SKOSConceptScheme scheme : voc.getSKOSConceptSchemes()) {
theso = theso + " " + scheme.getURI();
}
message = "new ontology loaded: " + theso;
// voc.getAsOWLOntology().getOntologyID();
// System.out.println("new ontology loaded: " + voc.getAsOWLOntology().getOntologyID());
skosVocabularies.put(voc.getURI(), voc);
dataSet = voc;
return true;
}
} catch (SKOSCreationException ex) {
Logger.getLogger(ImportSkosHelper.class.getName()).log(Level.SEVERE, null, ex);
message = ex.getMessage();
}
return false;
}
Aggregations