Skip to content

Commit

Permalink
Improvements of instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
propi committed Sep 14, 2020
1 parent 709303a commit 086adb2
Show file tree
Hide file tree
Showing 11 changed files with 348 additions and 323 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.github.propi.rdfrules.ruleset

import com.github.propi.rdfrules.algorithm.amie.AtomCounting
import com.github.propi.rdfrules.data.Graph
import com.github.propi.rdfrules.data.{Graph, TriplePosition}
import com.github.propi.rdfrules.index.{Index, IndexItem, TripleIndex}
import com.github.propi.rdfrules.rule.Rule
import com.github.propi.rdfrules.model.Model.PredictionType
import com.github.propi.rdfrules.rule.{Atom, Rule}
import com.github.propi.rdfrules.utils.TypedKeyMap
import com.github.propi.rdfrules.utils.extensions.TraversableOnceExtension._

Expand Down Expand Up @@ -40,13 +41,24 @@ object CoveredPaths {
val atomCounting = new AtomCounting {
implicit val tripleIndex: TripleIndex[Int] = thi
}
val /*(*/atoms/*, rest)*/ = part match {
case Part.Whole => rule.body.toSet + rule.head// -> Set.empty[Atom]
case Part.Body => rule.body.toSet// -> Set(rule.head)
case Part.Head => Set(rule.head)// -> rule.body.toSet
val (atoms, filter) = part match {
case Part.Whole => (rule.body.toSet + rule.head) -> ((x: Iterator[atomCounting.VariableMap]) => x)
case Part.Body(predictionType) =>
predictionType match {
case PredictionType.Existing => rule.body.toSet -> ((x: Iterator[atomCounting.VariableMap]) => x.filter(atomCounting.exists(Set(rule.head), _)))
case PredictionType.Missing => rule.body.toSet -> ((x: Iterator[atomCounting.VariableMap]) => x.filterNot(atomCounting.exists(Set(rule.head), _)))
case PredictionType.Complementary =>
val predicateIndex = thi.predicates(rule.head.predicate)
val isCompletelyMissing = predicateIndex.mostFunctionalVariable match {
case TriplePosition.Subject => (atom: Atom) => !predicateIndex.subjects.contains(atom.subject.asInstanceOf[Atom.Constant].value)
case TriplePosition.Object => (atom: Atom) => !predicateIndex.objects.contains(atom.`object`.asInstanceOf[Atom.Constant].value)
}
rule.body.toSet -> ((x: Iterator[atomCounting.VariableMap]) => x.filter(vm => isCompletelyMissing(vm.specifyAtom(rule.head))))
case PredictionType.All => rule.body.toSet -> ((x: Iterator[atomCounting.VariableMap]) => x)
}
case Part.Head => Set(rule.head) -> ((x: Iterator[atomCounting.VariableMap]) => x)
}
atomCounting.paths(atoms, new atomCounting.VariableMap(true))
//.filter(atomCounting.exists(rest, _))
filter(atomCounting.paths(atoms, new atomCounting.VariableMap(true)))
.map(variableMap => Rule.Simple(variableMap.specifyAtom(rule.head), rule.body.map(variableMap.specifyAtom))(TypedKeyMap()))
.foreach(f)
}
Expand All @@ -62,7 +74,7 @@ object CoveredPaths {

case object Head extends Part

case object Body extends Part
case class Body(predictionType: PredictionType) extends Part

case object Whole extends Part

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.github.propi.rdfrules.rule.{Measure, Rule, RulePattern, RulePatternMa
import com.github.propi.rdfrules.ruleset.ops.{Sortable, Treeable}
import com.github.propi.rdfrules.serialization.RuleSerialization._
import com.github.propi.rdfrules.utils.TypedKeyMap.Key
import com.github.propi.rdfrules.utils.extensions.TraversableOnceExtension.PimpedTraversableOnce
import com.github.propi.rdfrules.utils.serialization.{Deserializer, SerializationSize, Serializer}
import com.github.propi.rdfrules.utils.workers.Workers._
import com.github.propi.rdfrules.utils.{Debugger, TypedKeyMap}
Expand Down Expand Up @@ -81,6 +82,8 @@ class Ruleset private(val rules: Traversable[Rule.Simple], val index: Index, val

def instantiate(part: CoveredPaths.Part = CoveredPaths.Part.Whole): Traversable[CoveredPaths] = rules.view.map(CoveredPaths(_, part, index))

def +(ruleset: Ruleset): Ruleset = transform(rules.concat(ruleset.rules))

def headResolved: ResolvedRule = resolvedRules.head

def headResolvedOption: Option[ResolvedRule] = resolvedRules.headOption
Expand Down
Binary file modified dist/lib/core_2.12-1.0.0.jar
Binary file not shown.
Binary file modified dist/lib/http_2.12-1.0.0.jar
Binary file not shown.
6 changes: 3 additions & 3 deletions dist/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
<head>
<meta charset="UTF-8">
<title>RDFRules</title>
<link rel='stylesheet' href='css/home.css?v=1.4.2' type='text/css'/>
<link rel='stylesheet' href='css/home.css?v=1.4.3' type='text/css'/>
</head>
<body>
<header>
<h1>RDFRules</h1>
<div class="version">v1.4.2</div>
<div class="version">v1.4.3</div>
</header>
<main id="rdfrules"></main>
<script>
var endpoint = "http://localhost:8851/api";
</script>
<script src="js/tools.js"></script>
<script src="js/FileSaver.min.js"></script>
<script src="js/gui-opt.js?v=1.4.2"></script>
<script src="js/gui-opt.js?v=1.4.3"></script>
</body>
</html>
Loading

0 comments on commit 086adb2

Please sign in to comment.