Skip to content

Commit

Permalink
- Fixed issue with TTL and N3 format not loading
Browse files Browse the repository at this point in the history
  • Loading branch information
vguerbet committed Jun 20, 2024
1 parent 8c6ec84 commit a7c2c28
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 26 deletions.
18 changes: 15 additions & 3 deletions kb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
<excludes>
<exclude>**/WikidataCleaner.java</exclude>
</excludes>
<source>11</source>
<target>11</target>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
Expand All @@ -51,10 +51,22 @@
<artifactId>javafx-base</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-rio-turtle</artifactId>
<version>5.0.0-M3</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-rio-n3</artifactId>
<version>5.0.0-M3</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-storage</artifactId>
<version>4.3.2</version>
<version>5.0.0-M3</version>
<type>pom</type>
</dependency>
<dependency>
Expand Down
38 changes: 21 additions & 17 deletions kb/src/main/java/amie/data/KB.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static amie.data.U.decrease;
import static amie.data.U.decreasingKeys;
import static amie.data.U.increase;
import static com.hp.hpl.jena.sparql.engine.optimizer.reorder.ReorderTransformationBase.log;
//import static com.hp.hpl.jena.sparql.engine.optimizer.reorder.ReorderTransformationBase.log;

import amie.data.starpattern.SignedPredicate;
import amie.data.tuple.IntArrays;
Expand Down Expand Up @@ -33,6 +33,10 @@
import org.eclipse.rdf4j.rio.RDFFormat;
import org.eclipse.rdf4j.rio.RDFParser;
import org.eclipse.rdf4j.rio.Rio;
import org.eclipse.rdf4j.rio.helpers.AbstractRDFParser;
import org.eclipse.rdf4j.rio.turtle.TurtleParser;
import org.eclipse.rdf4j.rio.n3.N3Parser;


/**
* Class KB
Expand Down Expand Up @@ -221,25 +225,25 @@ protected void load(File f, String message)
+ String.format("%d s", (System.currentTimeMillis()
- time) / 1000));
}
if (f.getPath().endsWith(".ttl") || f.getPath().endsWith(".nt")) {
if (f.getPath().endsWith(RDFFormat.TURTLE.getDefaultFileExtension()) ||
f.getPath().endsWith(RDFFormat.N3.getDefaultFileExtension())) {
InputStream in = null;
try {
InputStream in = Files.newInputStream(Paths.get(f.getPath()));

if (f.getPath().endsWith(".ttl")){
StoreStatementToKB abstractRDFHandler = new StoreStatementToKB(this);
RDFParser rdfParser = Rio.createParser(RDFFormat.TURTLE);
rdfParser.setRDFHandler(abstractRDFHandler);
rdfParser.parse(in);
}
else{
StoreStatementToKB abstractRDFHandler = new StoreStatementToKB(this);
RDFParser rdfParser = Rio.createParser(RDFFormat.N3);
rdfParser.setRDFHandler(abstractRDFHandler);
rdfParser.parse(in);
}
in = Files.newInputStream(Paths.get(f.getPath()));
StoreStatementToKB abstractRDFHandler = new StoreStatementToKB(this);
AbstractRDFParser rdfParser ;
if (f.getPath().endsWith(RDFFormat.TURTLE.getDefaultFileExtension())){
rdfParser = new TurtleParser();
} else{
rdfParser = new N3Parser();
}
rdfParser.setRDFHandler(abstractRDFHandler);
rdfParser.parse(in);
} catch (Exception e) {
log.error("ParseInputFiles.parseTTLOrNTFileInLine parse TTL or NT error, filePath:{}", f.getPath(),e );
throw e ;
} finally {
if (in != null)
in.close() ;
}
} else {
for (String line : new FileLines(f, "UTF-8", message)) {
Expand Down
6 changes: 3 additions & 3 deletions kb/src/main/java/amie/data/StoreStatementToKB.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
public class StoreStatementToKB extends AbstractRDFHandler {

private static int counter = 0;
private AbstractKB kb;
private KB kb;
private static Map<String,String> prefixes=new HashMap<>();


StoreStatementToKB(AbstractKB kb){
StoreStatementToKB(KB kb){
this.kb = kb;
}
public void handleStatement(Statement st) {
String subject = getFormattedValue(String.valueOf(st.getSubject()));
String object = getFormattedValue(String.valueOf(st.getObject()));
String predict = getFormattedValue(String.valueOf(st.getPredicate()));
((KB) kb).add(subject, predict, object);
kb.add(subject, predict, object);
}

public String getFormattedValue(String value) {
Expand Down
2 changes: 1 addition & 1 deletion mining/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>amie3.5</finalName>
<finalName>amie3.5.1</finalName>
<appendAssemblyId>false</appendAssemblyId>
<outputDirectory>../bin</outputDirectory>
</configuration>
Expand Down
2 changes: 0 additions & 2 deletions mining/src/main/java/amie/mining/AMIE.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@

import amie.data.javatools.datatypes.MultiMap;
import org.apache.commons.lang.StringUtils;
import org.apache.zookeeper.Op;

/**
* Main class that implements the AMIE algorithm for rule mining on ontologies.
* The ontology must be provided as a list of TSV files where each line has the
Expand Down
6 changes: 6 additions & 0 deletions rules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,11 @@
<artifactId>kb</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

0 comments on commit a7c2c28

Please sign in to comment.