This repository has been archived by the owner on Oct 8, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3dd33b9
commit d5e6b6c
Showing
3 changed files
with
46 additions
and
19 deletions.
There are no files selected for viewing
22 changes: 5 additions & 17 deletions
22
...nce-common/src/main/scala/net/sansa_stack/inference/utils/JenaTripleToNTripleString.scala
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,33 +1,21 @@ | ||
package net.sansa_stack.inference.utils | ||
|
||
import org.apache.jena.graph.Triple | ||
import org.apache.jena.shared.PrefixMapping | ||
import org.apache.jena.sparql.util.FmtUtils | ||
|
||
|
||
/** | ||
* Convert a Jena Triple to an N-Triples string. | ||
* | ||
* @note it turns out, that it might be more efficient to use the Jena stream based writer API per partition. | ||
* | ||
* @author Lorenz Buehmann | ||
*/ | ||
class JenaTripleToNTripleString | ||
extends Function[Triple, String] | ||
with java.io.Serializable { | ||
override def apply(t: Triple): String = { | ||
val subStr = | ||
if (t.getSubject.isBlank) { | ||
s"_:${t.getSubject.getBlankNodeLabel}" | ||
} else { | ||
s"<${t.getSubject.getURI}>" | ||
} | ||
|
||
val objStr = | ||
if (t.getObject.isLiteral) { | ||
t.getObject | ||
} else if (t.getObject.isBlank) { | ||
s"_:${t.getObject}" | ||
} else { | ||
s"<${t.getObject}>" | ||
} | ||
s"$subStr <${t.getPredicate}> $objStr ." | ||
} | ||
override def apply(t: Triple): String = s"${FmtUtils.stringForTriple(t, null.asInstanceOf[PrefixMapping])} ." | ||
} | ||
|
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,40 @@ | ||
package net.sansa_stack.inference.utils | ||
|
||
/** | ||
* Some utils for logical combinations of boolean functions. | ||
*/ | ||
object PredicateUtils { | ||
|
||
implicit class RichPredicate[A](f: A => Boolean) extends (A => Boolean) { | ||
def apply(v: A): Boolean = f(v) | ||
|
||
/** | ||
* Logical 'and'. | ||
* | ||
* @param g | ||
* @return | ||
*/ | ||
def &&(g: A => Boolean): A => Boolean = { x: A => | ||
f(x) && g(x) | ||
} | ||
|
||
/** | ||
* Logical 'or'. | ||
* | ||
* @param g | ||
* @return | ||
*/ | ||
def ||(g: A => Boolean): A => Boolean = { x: A => | ||
f(x) || g(x) | ||
} | ||
|
||
/** | ||
* Logical 'not' | ||
* | ||
* @return | ||
*/ | ||
def unary_! : A => Boolean = { x: A => | ||
!f(x) | ||
} | ||
} | ||
} |