-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add the DurationLiteral class which implements RDFDataType * Fix wrong Supplier import * Add missing Test annotation * Cache QuerySource hashCode * Remove outdated TODO comment * Fix duration uri * Cleanup * Fix the conversion to a duration, that only contains seconds * Change the assertions of the failing RDFFileStorageTest * Fix comment * Update src/main/java/org/aksw/iguana/commons/time/DurationLiteral.java Co-authored-by: Alexander Bigerl <bigerl@mail.upb.de> * Check parameters for QuerySource and QueryList constructor * Remove unused comment * Additional parameter checking and adjust tests * Revert some parameter checks * Fix test assertions * Remove unused method * Change duration to dayTimeDuration --------- Co-authored-by: Alexander Bigerl <bigerl@mail.upb.de>
- Loading branch information
Showing
15 changed files
with
175 additions
and
24 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
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
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
91 changes: 91 additions & 0 deletions
91
src/main/java/org/aksw/iguana/commons/time/DurationLiteral.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 org.aksw.iguana.commons.time; | ||
|
||
import org.apache.jena.datatypes.DatatypeFormatException; | ||
import org.apache.jena.datatypes.RDFDatatype; | ||
import org.apache.jena.graph.impl.LiteralLabel; | ||
import org.apache.jena.vocabulary.XSD; | ||
|
||
import java.time.Duration; | ||
|
||
/** | ||
* This class is used to convert a Java Duration object to a typed RDF literal. The literal is typed as | ||
* xsd:dayTimeDuration.<br/> | ||
* TODO: This class temporarily fixes an issue with Jena. | ||
*/ | ||
public class DurationLiteral implements RDFDatatype { | ||
|
||
private final Duration duration; | ||
|
||
public DurationLiteral(Duration duration) { | ||
this.duration = duration; | ||
} | ||
|
||
public String getLexicalForm() { | ||
return duration.toString(); | ||
} | ||
|
||
@Override | ||
public String getURI() { | ||
return XSD.getURI() + "dayTimeDuration"; | ||
} | ||
|
||
@Override | ||
public String unparse(Object value) { | ||
return ((DurationLiteral) value).getLexicalForm(); | ||
} | ||
|
||
@Override | ||
public Object parse(String lexicalForm) throws DatatypeFormatException { | ||
return new DurationLiteral(Duration.parse(lexicalForm)); | ||
} | ||
|
||
@Override | ||
public boolean isValid(String lexicalForm) { | ||
try { | ||
Duration.parse(lexicalForm); | ||
return true; | ||
} catch (Exception e) { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isValidValue(Object valueForm) { | ||
return valueForm instanceof DurationLiteral; | ||
} | ||
|
||
@Override | ||
public boolean isValidLiteral(LiteralLabel lit) { | ||
return lit.getDatatype() instanceof DurationLiteral; | ||
} | ||
|
||
@Override | ||
public boolean isEqual(LiteralLabel value1, LiteralLabel value2) { | ||
return value1.getDatatype() == value2.getDatatype() && value1.getValue().equals(value2.getValue()); | ||
} | ||
|
||
@Override | ||
public int getHashCode(LiteralLabel lit) { | ||
return lit.getValue().hashCode(); | ||
} | ||
|
||
@Override | ||
public Class<?> getJavaClass() { | ||
return DurationLiteral.class; | ||
} | ||
|
||
@Override | ||
public Object cannonicalise(Object value) { | ||
return value; | ||
} | ||
|
||
@Override | ||
public Object extendedTypeDefinition() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public RDFDatatype normalizeSubType(Object value, RDFDatatype dt) { | ||
return dt; | ||
} | ||
} |
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
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
17 changes: 17 additions & 0 deletions
17
src/test/java/org/aksw/iguana/cc/query/source/impl/QuerySourceTest.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,17 @@ | ||
package org.aksw.iguana.cc.query.source.impl; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.nio.file.Path; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
public class QuerySourceTest { | ||
|
||
@Test | ||
public void testIllegalArguments() { | ||
assertThrows(IllegalArgumentException.class, () -> new FileLineQuerySource(null)); | ||
assertThrows(IllegalArgumentException.class, () -> new FileSeparatorQuerySource(null, "\n")); | ||
assertThrows(IllegalArgumentException.class, () -> new FolderQuerySource(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
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