-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from fkleedorfer/bugfix-list-and-numberformat
Bugfix for Blank node ordering, RDF lists and DecimalFormat
- Loading branch information
Showing
9 changed files
with
712 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
Andreas Textor <[email protected]> | ||
Florian Kleedorfer <[email protected]> |
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 |
---|---|---|
|
@@ -75,7 +75,7 @@ tasks.test { | |
} | ||
|
||
jacoco { | ||
toolVersion = "0.8.7" | ||
toolVersion = "0.8.12" | ||
} | ||
|
||
tasks.jacocoTestReport { | ||
|
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
55 changes: 55 additions & 0 deletions
55
src/main/java/de/atextor/turtle/formatter/RDFNodeComparatorFactory.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,55 @@ | ||
package de.atextor.turtle.formatter; | ||
|
||
import de.atextor.turtle.formatter.blanknode.BlankNodeMetadata; | ||
import org.apache.jena.rdf.model.RDFNode; | ||
import org.apache.jena.rdf.model.Resource; | ||
import org.apache.jena.shared.PrefixMapping; | ||
|
||
import java.util.Comparator; | ||
import java.util.Optional; | ||
|
||
public class RDFNodeComparatorFactory { | ||
|
||
private final PrefixMapping prefixMapping; | ||
private final BlankNodeMetadata blankNodeOrdering; | ||
private final RDFNodeComparator rdfNodeComparator = new RDFNodeComparator(); | ||
|
||
public RDFNodeComparatorFactory(PrefixMapping prefixMapping, BlankNodeMetadata blankNodeOrdering) { | ||
this.prefixMapping = prefixMapping; | ||
this.blankNodeOrdering = blankNodeOrdering; | ||
} | ||
|
||
public RDFNodeComparatorFactory(PrefixMapping prefixMapping) { | ||
this(prefixMapping, null); | ||
} | ||
|
||
public RDFNodeComparator comparator() { | ||
return rdfNodeComparator; | ||
} | ||
|
||
private class RDFNodeComparator implements Comparator<RDFNode> { | ||
@Override public int compare(RDFNode left, RDFNode right) { | ||
if (left.isURIResource()){ | ||
if (right.isURIResource()){ | ||
return prefixMapping.shortForm(left.asResource().getURI()).compareTo(prefixMapping.shortForm(right.asResource().getURI())); | ||
} else if (right.isAnon()) { | ||
return -1 ; // uris first | ||
} | ||
} else if (left.isAnon()) { | ||
if (right.isAnon()) { | ||
if (blankNodeOrdering != null) { | ||
return Optional.ofNullable(blankNodeOrdering.getOrder(left.asResource().asNode())) | ||
.orElse(Long.MAX_VALUE) | ||
.compareTo(Optional.ofNullable( | ||
blankNodeOrdering.getOrder(right.asResource().asNode())) | ||
.orElse(Long.MAX_VALUE)); | ||
} | ||
} else if (right.isResource()) { | ||
return 1; // uris first | ||
} | ||
} | ||
//fall-through for all other cases, especially if we don't have a blank node ordering | ||
return left.toString().compareTo(right.toString()); | ||
} | ||
} | ||
} |
Oops, something went wrong.