Skip to content

Commit

Permalink
Merge pull request #29 from tfrancart/issue15
Browse files Browse the repository at this point in the history
Issue11
  • Loading branch information
lmazuel committed Apr 18, 2017
2 parents 4ecc7c9 + 182a80c commit 896db66
Show file tree
Hide file tree
Showing 15 changed files with 672 additions and 102 deletions.
83 changes: 83 additions & 0 deletions Alignmnt_NEW_implementation
@@ -0,0 +1,83 @@

******************************Implémentation d'une nouvelle méthode d'alignement**************************************

-Prendre en compte un nouveau paramètre d'alignement: date de modification
NB: Cette nouvelle méthode doit être intégrer dans le package fr.onagui.alignment.method

1-Dans cette méthode il faudra implémenter la méthode toString() qui retournera le nom à donner à l'alignement

2-L'appel à ce nouvel alignement se fait dans la classe AlignmentControler dans le constructeur par :

methods = new HashSet<AbstractAlignmentMethod<ONTORES1, ONTORES2>>();
Set<Class<? extends AbstractAlignmentMethod>> classes = new HashSet<Class<? extends AbstractAlignmentMethod>>();
classes.add(NewAlignment.class.asSubclass(AbstractAlignmentMethod.class));
methods = buildInstancesFromClass(classes);

3-Dans la methode computeAndAddMapping nous allons ajouté en paramètre les nouveaux critères de tri par exemple :

-Nous pouvons ajouter deux variables date1 et date2 représentant respectivement une date de référence.
A partir ces dates nous allons lire la date de modification de chaque concept dans les deux classifications et supprimer les concepts ayant une date de modification antérieure à date1 pour la classification 1 et date2 pour la classification 2 avant l'alignement.

On a :
/*******lecture et stockage de tous les concepts présents dans les deux classifications*****/

TreeNodeOntologyObject<ONTORES1> userObject1 = (TreeNodeOntologyObject<ONTORES1>) rootFrom1.getUserObject();
Set<ONTORES1> concepts1 = OntoTools.getAllDescendants(container1, userObject1.getConcept());
TreeNodeOntologyObject<ONTORES2> userObject2 = (TreeNodeOntologyObject<ONTORES2>) rootFrom2.getUserObject();
Set<ONTORES2> concepts2 = OntoTools.getAllDescendants(container2, userObject2.getConcept());

/****************Suppression des concepts ayant une date antérieure*****************/

concepts1.removeIf(t -> {
Date datelue1=container1.getModifiedDate(t);
if(datelue1==null){
return false;
}else{
return datelue1.before(date1);
}

});

4- Nous obtenons la date de modification d'un concept grâce à la méthode getModifiedDate(ONTORES cpt).Cette méthode renvoi la date de modification du concept passé en paramètre.
Il est défini dans le package fr.onagui.alignment dans l'interface OntoContainer.
Nous allons implémenter cette méthode dans la classe SkosContainer.
Cette méthode éffectuera une requête SPARQL pour avoir la date de modification du concept :

/***********************************Requête SPARQL******************************** */

PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

select ?date where {
<cpt> dcterms:modified ?date

}

5- Dana la classe fr.onagui.gui.LabelParameterDialog il faudra ajouter les paramètres date 1 et 2 à définir dans le dialogue avant l'alignement.
Nous avons ajouter deux calendriers de type DatePicker de la librairie com.github.lgooddatepicker.
Une fois les dates définies par l'opérateur, à l'appui sur le bouton ok, nous les stockons grâce aux méthodes :

-setDate1(String date) et setDate2(String date)

Puis deux autres méthodes appelées getDate1AsDate() et getDate2AsDate() nous renvoient les dates(String) stockées en format Date.

6-Dans fr.onagui.gui.AlignementGUI nous allons instancier un objet LabelParameterDialog sur toute action sur le menu alignement. Le constructeur a besoin de certains paramètres(voir LabelParameterDialog).Nous pourrons ainsi récupérer les dates définies et les passées à la computeAndAddMapping :


labelParameterDialog = new LabelMethodParameterDialog(
AlignmentGUI.this,
labelMethod.getThreshold(),
alignmentControler.getLanguagesUsedInOnto(1),
alignmentControler.getLanguagesUsedInOnto(2)
);
labelParameterDialog.setVisible(true); // Blocking call

/*Fin dialogue->début alignement*/

alignmentControler.computeAndAddMapping(
method, listener, selected1, selected2,
labelParameterDialog.getDate1AsDate(),
labelParameterDialog.getDate2AsDate()
);


5 changes: 5 additions & 0 deletions pom.xml
Expand Up @@ -100,6 +100,11 @@
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
<dependency>
<groupId>com.github.lgooddatepicker</groupId>
<artifactId>LGoodDatePicker</artifactId>
<version>8.3.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/joda-time/joda-time -->
<dependency>
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/fr/onagui/alignment/OntoContainer.java
Expand Up @@ -4,6 +4,8 @@
package fr.onagui.alignment;

import java.net.URI;
import java.util.Date;
import java.util.Optional;
import java.util.Set;
import java.util.SortedSet;

Expand Down Expand Up @@ -80,6 +82,14 @@ public interface OntoContainer<ONTORES> {
*/
public Set<ONTORES> getChildren(ONTORES cpt);

/**
* Renvoi la date de modification du concept passé en paramètre
* @param cpt
* @return
*/

public Optional<Date> getModifiedDate(ONTORES cpt);

/** Les parents de ce concept
* @param cpt Un concept
* @return Les parents directs de ce concept
Expand Down
62 changes: 43 additions & 19 deletions src/main/java/fr/onagui/alignment/container/OWLAPIContainer.java
Expand Up @@ -4,13 +4,30 @@
package fr.onagui.alignment.container;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

import org.eclipse.rdf4j.model.Literal;
import org.eclipse.rdf4j.model.vocabulary.DCTERMS;
import org.eclipse.rdf4j.model.vocabulary.OWL;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.QueryLanguage;
import org.eclipse.rdf4j.query.TupleQuery;
import org.eclipse.rdf4j.query.TupleQueryResult;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.RepositoryException;
import org.eclipse.rdf4j.repository.sail.SailRepository;
import org.eclipse.rdf4j.rio.RDFFormat;
import org.eclipse.rdf4j.rio.RDFParseException;
import org.eclipse.rdf4j.sail.memory.MemoryStore;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.io.FileDocumentSource;
import org.semanticweb.owlapi.model.IRI;
Expand Down Expand Up @@ -39,7 +56,6 @@
public class OWLAPIContainer implements OntoContainer<OWLEntity> {

protected URI filename = null;

protected OWLOntology ontology = null;
protected OWLOntologyManager manager = null;
protected OWLDataFactory df;
Expand All @@ -49,6 +65,8 @@ public class OWLAPIContainer implements OntoContainer<OWLEntity> {

public OWLAPIContainer(URI filename) throws OWLOntologyCreationException {
try {


this.filename = filename;
manager = OWLManager.createOWLOntologyManager();
df = manager.getOWLDataFactory();
Expand All @@ -62,22 +80,23 @@ public OWLAPIContainer(URI filename) throws OWLOntologyCreationException {
getAllLanguageInLabels();
System.out.println("Found");

// try {
// System.out.println("Let's try Sesame");
// OwlTripleStore ts = Utilities.getOwlTripleStore(ontology, true);
// Repository sesame_repo = ts.getRepository();
// RepositoryConnection sesame_connect = sesame_repo.getConnection();
// System.out.println("I have: "+sesame_connect.size()+" statements");
// } catch (RepositoryException e) {
// System.err.println("Sesame Error!!!!");
// e.printStackTrace();

// try {
// System.out.println("Let's try Sesame");
// OwlTripleStore ts = Utilities.getOwlTripleStore(ontology, true);
// Repository sesame_repo = ts.getRepository();
// RepositoryConnection sesame_connect = sesame_repo.getConnection();
// System.out.println("I have: "+sesame_connect.size()+" statements");
// } catch (RepositoryException e) {
// System.err.println("Sesame Error!!!!");
// e.printStackTrace();
}
catch(RuntimeException e) {
e.printStackTrace();
throw e;
}
}

private class MyOwlVisitor extends OWLOntologyWalkerVisitor<OWLEntity> {
private OntoVisitor<OWLEntity> visitor;
public MyOwlVisitor(OWLOntologyWalker walker, OntoVisitor<OWLEntity> myvisitor) {
Expand All @@ -98,14 +117,14 @@ public OWLEntity visit(OWLNamedIndividual individual) {
return super.visit(individual);
}
}

@Override
public void accept(OntoVisitor<OWLEntity> visitor) {
OWLOntologyWalker ontoWalker = new OWLOntologyWalker(Collections.singleton(ontology));
OWLOntologyWalkerVisitor<OWLEntity> ontolvisitor = new MyOwlVisitor(ontoWalker, visitor);
ontoWalker.walkStructure(ontolvisitor);
}

@Override
public String getFormalism() {
return "owl";
Expand All @@ -119,7 +138,7 @@ public Set<OWLEntity> getAllConcepts() {
result.addAll(ontology.getIndividualsInSignature());
return result;
}

@Override
public boolean isIndividual(OWLEntity cpt) {
return cpt.isOWLNamedIndividual();
Expand All @@ -138,7 +157,7 @@ public Set<String> getAnnotations(OWLEntity cpt) {
// FIXME Support for OWL?
return new HashSet<String>();
}

/* (non-Javadoc)
* @see agui.alignment.OntoContainer#getPrefLabels(java.lang.Object)
*/
Expand Down Expand Up @@ -209,11 +228,11 @@ public OWLEntity getConceptFromURI(URI uri) {
return res;
return null;
}

@Override
public Set<OWLEntity> getChildren(OWLEntity cpt) {
if(!cpt.isOWLClass()) return new HashSet<OWLEntity>();

Set<OWLEntity> entities = new HashSet<OWLEntity>();
Set<OWLEntity> result = new HashSet<OWLEntity>();
OWLClass localRootClass = cpt.asOWLClass();
Expand All @@ -234,11 +253,11 @@ public Set<OWLEntity> getChildren(OWLEntity cpt) {
}
return result;
}

@Override
public Set<OWLEntity> getParents(OWLEntity cpt) {
if(!cpt.isOWLClass()) return new HashSet<OWLEntity>();

Set<OWLEntity> entities = new HashSet<OWLEntity>();
Set<OWLEntity> result = new HashSet<OWLEntity>();
OWLClass localRootClass = cpt.asOWLClass();
Expand Down Expand Up @@ -305,4 +324,9 @@ public OWLReasoner getReasoner() {
public Set<String> getLabels(OWLEntity cpt, String prop) {
throw new UnsupportedOperationException("Not supported in OWL for now");
}

@Override
public Optional<Date> getModifiedDate(OWLEntity cpt) {
throw new UnsupportedOperationException("Not supported in OWL for now");
}
}

0 comments on commit 896db66

Please sign in to comment.