-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added parsing of SSSOM to eval client
- Loading branch information
Showing
12 changed files
with
308 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>de.uni-mannheim.informatik.dws.melt</groupId> | ||
<artifactId>SSSOMMatcher</artifactId><!-- id used as matcher id in descriptor file of seals package --> | ||
<packaging>jar</packaging> | ||
<version>1.0</version><!-- version appearing in descriptor file of seals package --> | ||
<description>simple SSSOM Matcher</description><!-- description appearing in descriptor file of seals package --> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
|
||
<oaei.mainClass>de.uni_mannheim.informatik.dws.melt.demomatcher.SSSOMMatcher</oaei.mainClass><!-- mandatory: this class has to implement IOntologyMatchingToolBridge --> | ||
|
||
<oaei.copyright>(C) Mannheim, 2019</oaei.copyright> <!--optional copyright appearing in the seals descriptor file --> | ||
<oaei.license>GNU Lesser General Public License 2.1 or above</oaei.license> <!--optional license appearing in the seals descriptor file --> | ||
|
||
<matching.version>3.4-SNAPSHOT</matching.version> <!-- version for all matching related packages --> | ||
</properties> | ||
|
||
<!-- Accessing the resources: | ||
- all files in "oaei-resources" folder are stored in the current working directory and can be accessed with | ||
Files.readAllLines(Paths.get("oaei-resources", "configuration_oaei.txt")); | ||
- all files in "src/main/resources" folder are compiled to the resulting jar and can be accessed with | ||
getClass().getClassLoader().getResourceAsStream("configuration_jar.txt"); | ||
--> | ||
|
||
<dependencies> | ||
<!-- dependency for jena matchers - for other matchers you can replace it with artifactId: matching-base --> | ||
<dependency> | ||
<groupId>de.uni-mannheim.informatik.dws.melt</groupId> | ||
<artifactId>matching-jena</artifactId> | ||
<version>${matching.version}</version> | ||
</dependency> | ||
|
||
<!-- This dependency is necessary for seals_external. It contains the cli wrapper. --> | ||
<dependency> | ||
<groupId>de.uni-mannheim.informatik.dws.melt</groupId> | ||
<artifactId>receiver-cli</artifactId> | ||
<version>${matching.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>de.uni-mannheim.informatik.dws.melt</groupId> | ||
<artifactId>matching-eval</artifactId> | ||
<version>${matching.version}</version> | ||
<scope>test</scope> | ||
<!-- only in test scope, can only be used when running tests. | ||
You can also remove the scope but then remove the whole dependency when packaging the matcher. | ||
Otherwise you get a lot of unused dependencies in your matcher.--> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-log4j12</artifactId> | ||
<version>1.7.36</version> | ||
</dependency> | ||
|
||
|
||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<version>5.9.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<version>5.9.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
|
||
<!-- the following plugin will generate a seals assembly --> | ||
<plugin> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<version>3.4.2</version> | ||
<dependencies> | ||
<dependency> | ||
<groupId>de.uni-mannheim.informatik.dws.melt</groupId> | ||
<artifactId>matching-assembly</artifactId> | ||
<version>${matching.version}</version> | ||
</dependency> | ||
</dependencies> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals><goal>single</goal></goals> | ||
<!-- there exists three descriptors: | ||
1) "seals" - removes all dependencies available in seals client regardless of their version. | ||
2) "seals_all_deps" - adds all dependencies of your project (please note that this can cause problems when using jena for example) | ||
3) "seals_external" - creates a wrapper around the matcher so that no inference with seals happens(the matcher has to log to std err only).--> | ||
<configuration><descriptorRefs><descriptorRef>seals_external</descriptorRef></descriptorRefs></configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>3.0.0-M7</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
91 changes: 91 additions & 0 deletions
91
...OMMatcher/src/main/java/de/uni_mannheim/informatik/dws/melt/demomatcher/SSSOMMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package de.uni_mannheim.informatik.dws.melt.demomatcher; | ||
|
||
import de.uni_mannheim.informatik.dws.melt.matching_base.MatcherURL; | ||
import de.uni_mannheim.informatik.dws.melt.matching_jena.OntologyCacheJena; | ||
import de.uni_mannheim.informatik.dws.melt.yet_another_alignment_api.Alignment; | ||
import de.uni_mannheim.informatik.dws.melt.yet_another_alignment_api.DefaultExtensions.SSSOM; | ||
import de.uni_mannheim.informatik.dws.melt.yet_another_alignment_api.SSSOMSerializer; | ||
import java.io.File; | ||
import java.net.URL; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import org.apache.jena.ontology.OntModel; | ||
import org.apache.jena.ontology.OntResource; | ||
import org.apache.jena.rdf.model.NodeIterator; | ||
import org.apache.jena.rdf.model.RDFNode; | ||
import org.apache.jena.util.iterator.ExtendedIterator; | ||
import org.apache.jena.vocabulary.RDFS; | ||
|
||
/** | ||
* A very simple SSSOM matcher. | ||
*/ | ||
public class SSSOMMatcher extends MatcherURL { | ||
|
||
@Override | ||
public URL match(URL sourceURL, URL targetURL, URL inputAlignment) throws Exception { | ||
|
||
OntModel source = OntologyCacheJena.get(sourceURL, OntologyCacheJena.DEFAULT_JENA_ONT_MODEL_SPEC); | ||
OntModel target = OntologyCacheJena.get(targetURL, OntologyCacheJena.DEFAULT_JENA_ONT_MODEL_SPEC); | ||
|
||
Alignment alignment = new Alignment(); | ||
matchResources(source.listClasses(), target.listClasses(), alignment);//match only classes | ||
|
||
File alignmentFile = File.createTempFile("alignment", ".rdf"); | ||
|
||
alignment.addExtensionValue(SSSOM.MAPPING_SET_TITLE, "A simple SSSOM mapping."); | ||
|
||
SSSOMSerializer.serialize(alignment, alignmentFile); | ||
return alignmentFile.toURI().toURL(); | ||
} | ||
|
||
|
||
private void matchResources(ExtendedIterator<? extends OntResource> sourceResources, ExtendedIterator<? extends OntResource> targetResources, Alignment alignment) { | ||
HashMap<String, String> text2URI = new HashMap<>(); | ||
while (sourceResources.hasNext()) { | ||
OntResource source = sourceResources.next(); | ||
for(String s : getStringRepresentation(source)) | ||
text2URI.put(s, source.getURI()); | ||
} | ||
while (targetResources.hasNext()) { | ||
OntResource target = targetResources.next(); | ||
for(String s : getStringRepresentation(target)){ | ||
String sourceURI = text2URI.get(s); | ||
if(sourceURI != null){ | ||
alignment.add(sourceURI, target.getURI()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private Set<String> getStringRepresentation(OntResource resource) { | ||
Set<String> texts = new HashSet<>(); | ||
String uri = resource.getURI(); | ||
if(uri == null) | ||
return texts; | ||
NodeIterator labelIterator = resource.listPropertyValues(RDFS.label); | ||
while(labelIterator.hasNext()){ | ||
RDFNode label = labelIterator.next(); | ||
if(label.isLiteral()){ | ||
texts.add(label.asLiteral().getLexicalForm().toLowerCase()); | ||
} | ||
} | ||
String fragment = getUriFragment(resource.getURI()); | ||
if(fragment != null) | ||
texts.add(fragment.toLowerCase().replace("_", " ")); | ||
return texts; | ||
} | ||
|
||
public static String getUriFragment(String uri){ | ||
int lastIndex = uri.lastIndexOf("#"); | ||
if(lastIndex >= 0){ | ||
return uri.substring(lastIndex + 1); | ||
} | ||
lastIndex = uri.lastIndexOf("/"); | ||
if(lastIndex >= 0){ | ||
return uri.substring(lastIndex + 1); | ||
} | ||
return null; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Root logger option | ||
log4j.rootLogger=INFO, stdout | ||
|
||
# Direct log messages to stdout | ||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender | ||
log4j.appender.stdout.Target=System.out | ||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout | ||
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%-30.30t] %-4L in %-20.20c{1} - %m%n |
18 changes: 18 additions & 0 deletions
18
...atcher/src/test/java/de/uni_mannheim/informatik/dws/melt/demomatcher/EvaluateMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package de.uni_mannheim.informatik.dws.melt.demomatcher; | ||
|
||
import de.uni_mannheim.informatik.dws.melt.matching_data.TrackRepository; | ||
import de.uni_mannheim.informatik.dws.melt.matching_eval.ExecutionResult; | ||
import de.uni_mannheim.informatik.dws.melt.matching_eval.ExecutionResultSet; | ||
import de.uni_mannheim.informatik.dws.melt.matching_eval.Executor; | ||
import org.junit.jupiter.api.Test; | ||
|
||
|
||
public class EvaluateMatcher { | ||
|
||
@Test | ||
public void evalSimpleMatcher(){ | ||
ExecutionResultSet result = Executor.run(TrackRepository.Anatomy.Default, new SSSOMMatcher()); | ||
ExecutionResult r = result.iterator().next(); | ||
System.out.print(r.getSystemAlignment()); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...SOMMatcher/src/test/java/de/uni_mannheim/informatik/dws/melt/demomatcher/TestPackage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package de.uni_mannheim.informatik.dws.melt.demomatcher; | ||
|
||
import de.uni_mannheim.informatik.dws.melt.matching_base.external.seals.MatcherSeals; | ||
import de.uni_mannheim.informatik.dws.melt.matching_data.TrackRepository; | ||
import de.uni_mannheim.informatik.dws.melt.matching_eval.ExecutionResult; | ||
import de.uni_mannheim.informatik.dws.melt.matching_eval.Executor; | ||
import java.io.File; | ||
import java.nio.file.Paths; | ||
|
||
/** | ||
* This class tests the generated seals package. | ||
* The exit code is important because it used in the continuouns integration | ||
* pipeline (CI) in github to test the package. | ||
*/ | ||
public class TestPackage { | ||
public static void main(String[] args) { | ||
// cache seals client in CI (thus the location .m2 because it is cache already) | ||
File sealsClient = Paths.get(System.getProperty("user.home"), ".m2", "seals_client.jar").toFile(); | ||
MatcherSeals sealsMatcher = new MatcherSeals(new File("target/simpleSealsMatcher-1.0-seals_external.zip"), sealsClient); | ||
ExecutionResult result = Executor.runSingle(TrackRepository.Anatomy.Default.getFirstTestCase(), sealsMatcher); | ||
|
||
if(result.getSystemAlignment().isEmpty()){ | ||
System.exit(1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...a/de/uni_mannheim/informatik/dws/melt/yet_another_alignment_api/SSSOMFormatException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package de.uni_mannheim.informatik.dws.melt.yet_another_alignment_api; | ||
|
||
/** | ||
* Exception representing a error when data does not fit to SSSOM schema | ||
*/ | ||
public class SSSOMFormatException extends Exception { | ||
|
||
private static final long serialVersionUID = 5451825154955645498L; | ||
|
||
|
||
public SSSOMFormatException(String msg) { | ||
super(msg); | ||
} | ||
|
||
public SSSOMFormatException(String msg, Throwable inner) { | ||
super(msg, inner); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters