Commit 4c2bf524 authored by pichot's avatar pichot
Browse files

Add facilities to export (rdf format) the matchings and selected definitions

parent 7bdccea1
......@@ -30,6 +30,7 @@ import java.util.HashSet;
import java.util.Set;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import org.apache.log4j.PropertyConfigurator;
......@@ -893,6 +894,8 @@ public class AML
System.out.println("Classes: " + source.count(EntityType.CLASS));
System.out.println("Individuals: " + source.count(EntityType.INDIVIDUAL));
System.out.println("Properties: " + (source.count(EntityType.DATA)+source.count(EntityType.OBJECT)));
System.out.println("Lexicon: " + (source.getLexicon().size()));//cpichotjv2020
System.out.println("Definitions: " + (source.getDefinitions().size()));//cpichotjv2020
time = System.currentTimeMillis()/1000;
System.out.println("Loading target ontology");
target = new Ontology(tgt);
......@@ -901,6 +904,8 @@ public class AML
System.out.println("Classes: " + target.count(EntityType.CLASS));
System.out.println("Individuals: " + target.count(EntityType.INDIVIDUAL));
System.out.println("Properties: " + (target.count(EntityType.DATA)+target.count(EntityType.OBJECT)));
System.out.println("Lexicon: " + (target.getLexicon().size()));//cpichotjv2020
System.out.println("Definitions: " + (target.getDefinitions().size()));//cpichotjv2020
System.out.println("Direct Relationships: " + rels.relationshipCount());
time = System.currentTimeMillis()/1000;
System.out.println("Running transitive closure on RelationshipMap");
......@@ -921,9 +926,13 @@ public class AML
sw.extendLexicons();
ParenthesisExtender p = new ParenthesisExtender();
p.extendLexicons();
System.out.println("Finished!");
System.out.println("Finished!");
JOptionPane.showMessageDialog(null,
"You are using the AML modified version\n"
+ "allowing for definitions (from target)\n"
+ " and exactMatchings exports ", "WARNING", JOptionPane.PLAIN_MESSAGE);//cpichotjv2020
}
public void openOntologies(URI src, URI tgt) throws OWLOntologyCreationException
{
closeOntologies();
......@@ -1105,6 +1114,18 @@ public class AML
needSave = false;
}
public void saveAlignmentTSV2(String file) throws Exception //cpichotjv2020
{
a.saveTSV2(file);
//needSave = false;
}
public void saveAlignmentTSV3(String file) throws Exception //cpichotjv2020
{
a.saveTSV3(file);
//needSave = false;
}
public void setAlignment(Alignment maps)
{
a = maps;
......@@ -1297,7 +1318,13 @@ public class AML
if(userInterface != null)
userInterface.refresh();
}
public void maskExisting() //cpichotjv2020
{
a.setMaskExisting(!a.getMaskExisting());
userInterface.refresh();
}
public void startGUI()
{
//Set the Nimbus look and feel
......
......@@ -66,6 +66,11 @@ public class Alignment implements Collection<Mapping>
private Ontology target;
//Link to the URIMap
private URIMap uris;
//Number of existing matches //cpichotjv2020
private int nbExistingMatch;
//Mask existing matches //cpichotjv2020
private boolean maskExisting;
//Constructors
......@@ -81,6 +86,8 @@ public class Alignment implements Collection<Mapping>
source = aml.getSource();
target = aml.getTarget();
uris = aml.getURIMap();
nbExistingMatch = 0; //cpichotjv2020
maskExisting = false; //cpichotjv2020
}
/**
......@@ -93,9 +100,12 @@ public class Alignment implements Collection<Mapping>
if(file.endsWith(".rdf") || file.endsWith(".xml"))
loadMappingsRDF(file);
else if(file.endsWith(".tsv"))
loadMappingsTSV(file);
//loadMappingsTSV(file);//cpichotjv2020
loadMappingsTSV2(file);//cpichotjv2020
else
throw new Exception("Unrecognized alignment format!");
nbExistingMatch = 0; //cpichotjv2020
maskExisting = false; //cpichotjv2020
}
/**
......@@ -106,9 +116,77 @@ public class Alignment implements Collection<Mapping>
{
this();
addAll(a);
nbExistingMatch = 0; //cpichotjv2020
maskExisting = false; //cpichotjv2020
}
//Public Methods
/**
* Load existing matches from the source ontology //cpichotjv2020
*/
public void loadExistingMatch()
{
source = aml.getSource();
target = aml.getTarget();
nbExistingMatch = 0;
//cpichotjv2020 for (int i=0; i< source.classCount();i++){
for (int i=0; i< source.count();i++){
Set<String> matchesTable = source.getExistingMatches(i);
if (matchesTable.size() > 0){
for (int matchIndex = 0; matchIndex < matchesTable.size(); matchIndex++){
String existingMatch = matchesTable.toArray()[matchIndex].toString();
//check if the class (i) belongs to the present mapping
for(Mapping m : maps){
if (m.getSourceId() == i){
//check if this is the same mapping
int targetId = m.getTargetId();
if (target.getURI(targetId).equals(existingMatch)){
//System.out.println("same matching");
//System.out.println(existingMatch);
//System.out.println(target.getURI(targetId));
//set status3
m.setStatus3(MappingStatus.CORRECT);
nbExistingMatch = nbExistingMatch + 1;
}
else {
//System.out.println("different matching");
//System.out.println(existingMatch);
//System.out.println(target.getURI(targetId));
}
}
else{
// the class (i) does not belong to the present mapping
}
}
}
}
}
}
/**
* Set maskExisting //cpichotjv2020
*/
public void setMaskExisting(boolean newval)
{
this.maskExisting = newval;
}
/**
* Get maskExisting //cpichotjv2020
*/
public boolean getMaskExisting()
{
return this.maskExisting;
}
/**
* Get nbExistingMatch //cpichotjv2020
*/
public int getNbExistingMatch()
{
return this.nbExistingMatch;
}
/**
* Adds a new Mapping to the Alignment if it is non-redundant
......@@ -190,6 +268,51 @@ public class Alignment implements Collection<Mapping>
return check;
}
}
public boolean add2(int sourceId, int targetId, double sim, MappingRelation r, MappingStatus s, MappingStatus s2)//cpichotjv2020
{
//Unless the Alignment is internal, we can't have a mapping
//involving entities that exist in both ontologies (they are
//the same entity, and therefore shouldn't map with other
//entities in either ontology)
if(!aml.matchSameURI() && (source.contains(targetId) || target.contains(sourceId)))
return false;
//Construct the Mapping
Mapping m = new Mapping(sourceId, targetId, sim, r);
m.setStatus(s);
m.setStatus2(s2);
//If it isn't listed yet, add it
if(!sourceMaps.contains(sourceId,targetId))
{
maps.add(m);
sourceMaps.add(sourceId, targetId, m);
targetMaps.add(targetId, sourceId, m);
return true;
}
//Otherwise update the similarity
else
{
m = sourceMaps.get(sourceId,targetId);
boolean check = false;
if(m.getSimilarity() < sim)
{
m.setSimilarity(sim);
check = true;
}
if(!m.getRelationship().equals(r))
{
m.setRelationship(r);
check = true;
}
if(!m.getStatus().equals(s))
{
m.setStatus(s);
check = true;
}
return check;
}
}
/**
* Adds a new Mapping to the Alignment if it is non-redundant
......@@ -226,6 +349,19 @@ public class Alignment implements Collection<Mapping>
return add(id2,id1,sim,r,s);
return false;
}
public boolean add2(String sourceURI, String targetURI, double sim, MappingRelation r, MappingStatus s, MappingStatus s2) //cpichotjv2020
{
int id1 = uris.getIndex(sourceURI);
int id2 = uris.getIndex(targetURI);
if(id1 == -1 || id2 == -1)
return false;
if(aml.getSource().contains(id1) && aml.getTarget().contains(id2))
return add2(id1,id2,sim,r,s,s2);//cpichotjv2020
else if(aml.getSource().contains(id2) && aml.getTarget().contains(id1))
return add2(id2,id1,sim,r,s,s2);//cpichotjv2020
return false;
}
@Override
public boolean add(Mapping m)
......@@ -1065,6 +1201,55 @@ public class Alignment implements Collection<Mapping>
outStream.close();
}
/** //cpichotjv2020
* Saves the Alignment into a .tsv file in AML format
* @param file: the output file
*/
public void saveTSV2(String file) throws FileNotFoundException
{
PrintWriter outStream = new PrintWriter(new FileOutputStream(file));
PrintWriter outStreamDef = new PrintWriter(new FileOutputStream(file + ".rdf"));
outStream.println("#AgreementMakerLight DEFINITION FROM Alignment File");
outStream.println("#Source ontology:\t" + source.getURI());
outStream.println("#Target ontology:\t" + target.getURI());
outStream.println("Source URI\tSource Label\tTarget URI\tTarget Label\tSimilarity\tRelationship\tStatus");
outStreamDef.println("<?xml version=\"1.0\" ?>");
outStreamDef.println("<rdf:RDF");
outStreamDef.println("xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'");
outStreamDef.println("xmlns:status='http://art.uniroma2.it/ontologies/vocbench#'");
outStreamDef.println("xmlns:skos='http://www.w3.org/2004/02/skos/core#'>");
for(Mapping m : maps)
outStream.println(m.toString2());
outStream.close();
for(Mapping m : maps)
if(!m.toString2Def().equals(""))
outStreamDef.println(m.toString2Def());
outStreamDef.println("</rdf:RDF>");
outStreamDef.close();
}
/** //cpichotjv2020
* Saves the Alignment into a .tsv file in AML format
* @param file: the output file
*/
public void saveTSV3(String file) throws FileNotFoundException
{
PrintWriter outStreamMatch = new PrintWriter(new FileOutputStream(file + ".rdf"));
outStreamMatch.println("<?xml version=\"1.0\" ?>");
outStreamMatch.println("<rdf:RDF");
outStreamMatch.println("xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'");
outStreamMatch.println("xmlns:skos='http://www.w3.org/2004/02/skos/core#'>");
for(Mapping m : maps)
if(!m.toString2Match().equals(""))
outStreamMatch.println(m.toString2Match());
outStreamMatch.println("</rdf:RDF>");
outStreamMatch.close();
}
@Override
public int size()
{
......@@ -1260,4 +1445,83 @@ public class Alignment implements Collection<Mapping>
}
inStream.close();
}
private void loadMappingsTSV2(String file) throws Exception //cpichotjv2020
{
System.out.println(file);
System.out.println(file + ".DEFINITIONS");
BufferedReader inStream = new BufferedReader(new FileReader(file));
//BufferedReader inStream2 = new BufferedReader(new FileReader(file));
BufferedReader inStream2 = new BufferedReader(new FileReader(file + ".DEFINITIONS"));//cpichotjv2020
//First line contains the reference to AML
inStream.readLine();
//Second line contains the source ontology
inStream.readLine();
//Third line contains the target ontology
inStream.readLine();
//Fourth line contains the headers
inStream.readLine();
//First line contains the reference to AML
inStream2.readLine();
//Second line contains the source ontology
inStream2.readLine();
//Third line contains the target ontology
inStream2.readLine();
//Fourth line contains the headers
inStream2.readLine();
//And from the fifth line forward we have mappings
String line;
String line2;
while((line = inStream.readLine()) != null)
{
line2 = inStream2.readLine();
String[] col = line.split("\t");
String[] col2 = line2.split("\t");//cpichotjv2020
//First column contains the source uri
String sourceURI = col[0];
//Third contains the target uri
String targetURI = col[2];
//Fifth contains the similarity
String measure = col[4];
//Parse it, assuming 1 if a valid measure is not found
double similarity = 1;
if(measure != null)
{
try
{
similarity = Double.parseDouble(measure);
if(similarity < 0 || similarity > 1)
similarity = 1;
}
catch(Exception ex){/*Do nothing - use the default value*/};
}
//The sixth column contains the type of relation
MappingRelation rel;
if(col.length > 5)
rel = MappingRelation.parseRelation(col[5]);
//For compatibility with previous tsv format without listed relation
else
rel = MappingRelation.EQUIVALENCE;
//The seventh column, if it exists, contains the status of the Mapping
MappingStatus st;
MappingStatus st2;//cpichotjv2020
if(col.length > 6)
st = MappingStatus.parseStatus(col[6]);
//For compatibility with previous tsv format without listed relation
else
st = MappingStatus.UNKNOWN;
if(col2.length > 6)
st2 = MappingStatus.parseStatus(col2[6]);
//For compatibility with previous tsv format without listed relation
else
st2 = MappingStatus.UNKNOWN;
add2(sourceURI, targetURI, similarity, rel, st, st2);
}
inStream.close();
inStream2.close();
}
}
\ No newline at end of file
......@@ -43,6 +43,11 @@ public class Mapping implements Comparable<Mapping>
private MappingRelation rel;
//The status of the Mapping
private MappingStatus s;
//The status of the DefinitionMapping //cpichotjv2020
private MappingStatus s2;
//The status of the existingMatch //cpichotjv2020
private MappingStatus s3;
//Constructors
......@@ -58,6 +63,8 @@ public class Mapping implements Comparable<Mapping>
similarity = 1.0;
rel = MappingRelation.EQUIVALENCE;
s = MappingStatus.UNKNOWN;
s2 = MappingStatus.UNKNOWN;//cpichotjv2020
s3 = MappingStatus.UNKNOWN;//cpichotjv2020
}
/**
......@@ -73,6 +80,8 @@ public class Mapping implements Comparable<Mapping>
similarity = Math.round(sim*10000)/10000.0;
rel = MappingRelation.EQUIVALENCE;
s = MappingStatus.UNKNOWN;
s2 = MappingStatus.UNKNOWN;//cpichotjv2020
s3 = MappingStatus.UNKNOWN;//cpichotjv2020
}
/**
......@@ -89,6 +98,8 @@ public class Mapping implements Comparable<Mapping>
similarity = Math.round(sim*10000)/10000.0;
rel = r;
s = MappingStatus.UNKNOWN;
s2 = MappingStatus.UNKNOWN;//cpichotjv2020
s3 = MappingStatus.UNKNOWN;//cpichotjv2020
}
/**
......@@ -102,6 +113,9 @@ public class Mapping implements Comparable<Mapping>
similarity = m.similarity;
rel = m.rel;
s = m.s;
s2 = m.s2; //cpichotjv2020
s3 = m.s3; //cpichotjv2020
}
//Public Methods
......@@ -189,6 +203,22 @@ public class Mapping implements Comparable<Mapping>
return s;
}
/** //cpichotjv2020
* @return the status of this Definition Mapping
*/
public MappingStatus getStatus2()
{
return s2;
}
/** //cpichotjv2020
* @return the status of this Definition Mapping
*/
public MappingStatus getStatus3()
{
return s3;
}
/**
* @return the id of the target term
*/
......@@ -230,7 +260,27 @@ public class Mapping implements Comparable<Mapping>
public void setStatus(MappingStatus s)
{
this.s = s;
}
/** //cpichot2020
* Sets the Definition MappingStatus of this Mapping
* @param s: the Mapping status to set
*/
public void setStatus2(MappingStatus s)
{
this.s2 = s;
}
/** //cpichot2020
* Sets the Definition MappingStatus of this Mapping
* @param s: the Mapping status to set
*/
public void setStatus3(MappingStatus s)
{
this.s3 = s;
}
/**
* @return the Mapping in String form, formatted for the AML GUI
......@@ -272,4 +322,68 @@ public class Mapping implements Comparable<Mapping>
out += "\t" + s;
return out;
}
//cpichotjv2020
public String toString2()
{
AML aml = AML.getInstance();
URIMap uris = aml.getURIMap();
Ontology source = aml.getSource();
Ontology target = aml.getTarget();
String out = uris.getURI(sourceId) + "\t" + source.getName(sourceId) +
"\t" + uris.getURI(targetId) + "\t" + target.getName(targetId) +
"\t" + similarity + "\t" + rel.toString();
if(!s2.equals(MappingStatus.UNKNOWN))
out += "\t" + s2;
return out;
}//cpichotjv2020
//cpichotjv2020
public String defString(String myString, String myCutter){ //CP
String[] myStringSplitted = myString.split(myCutter);
String out = myStringSplitted [0];
for(int i = 1; i < myStringSplitted.length-1; i++){
out += myCutter + myStringSplitted [i];
}
out += myCutter + "i_def_" + myStringSplitted [myStringSplitted.length-1];
return out;
}//cpichotjv2020
//cpichotjv2020
public String toString2Def()
{
AML aml = AML.getInstance();
URIMap uris = aml.getURIMap();
Ontology source = aml.getSource();
Ontology target = aml.getTarget();
String out = "";
if(s2.equals(MappingStatus.CORRECT)){
out = "<rdf:Description rdf:about='" + uris.getURI(sourceId) + "'>";
out += "\n <skos:definition rdf:resource='" + defString(uris.getURI(sourceId),"/") + "'/>";
out += "\n</rdf:Description>";
out += "\n\n<rdf:Description rdf:about='" + defString(uris.getURI(sourceId),"/") + "'>";
out += "\n <status:hasSource rdf:datatype='http://www.w3.org/2001/XMLSchema#string'>" +
target.getURI() + "</status:hasSource>";
out += "\n <rdf:value xml:lang='en'>" + target.getDefinitions(targetId).replaceAll("(^\\[|\\]$)", "") + "</rdf:value>";
out += "\n</rdf:Description>\n";
}
return out;
}//cpichotjv2020
public String toString2Match()
{
AML aml = AML.getInstance();
URIMap uris = aml.getURIMap();
//Ontology source = aml.getSource();
//Ontology target = aml.getTarget();
String out = "";
if(s.equals(MappingStatus.CORRECT)){
out = "<rdf:Description rdf:about='" + uris.getURI(sourceId) + "'>";
out += "\n <skos:exactMatch rdf:resource='" + uris.getURI(targetId) + "'/>";
out += "\n</rdf:Description>\n";
}
return out;
}
}
This diff is collapsed.
This diff is collapsed.
......@@ -81,6 +81,11 @@ public class Ontology
//Its set of obsolete classes
protected HashSet<Integer> obsolete;
//Its definitions //cpichotjv2020
protected Definitions definitions; //cpichotjv2020
//Its matches //cpichotjv2020
protected ExistingMatches existingMatches; //cpichotjv2020
//Global variables & data structures
protected AML aml;
protected boolean useReasoner;
......@@ -118,6 +123,8 @@ public class Ontology
useReasoner = aml.useReasoner();
uris = aml.getURIMap();
rm = aml.getRelationshipMap();
definitions = new Definitions(); //cpichotjv2020
existingMatches = new ExistingMatches(); //cpichotjv2020
}
/**
......@@ -208,6 +215,8 @@ public class Ontology
aml = null;
uris = null;
rm = null;
definitions = null;//cpichotjv2020
existingMatches = null;//cpichotjv2020
}
/**
......@@ -277,6 +286,40 @@ public class Ontology
return lex;
}
/**
* @return the Ontology's Definitions //cpichotjv2020
*/