Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging Rule Sets with Different Indexes #61

Open
nvkp opened this issue May 20, 2021 · 1 comment
Open

Merging Rule Sets with Different Indexes #61

nvkp opened this issue May 20, 2021 · 1 comment

Comments

@nvkp
Copy link

nvkp commented May 20, 2021

The current library is not able to handle a concatenation of two rule sets with a different index. I provide a script and sample data on which the problem can be replicated:

sbt clean compile run
rules count from the first task: 6
rules count from the second task: 45
[error] (run-main-0) java.util.NoSuchElementException: None.get
[error] java.util.NoSuchElementException: None.get
[error]         at scala.None$.get(Option.scala:529)
[error]         at scala.None$.get(Option.scala:527)
[error]         at com.github.propi.rdfrules.index.TripleItemIndex.getTripleItem(TripleItemIndex.scala:16)
...
... see stacktrace.txt

I thought if the indexes are not equal, they could be merged together through their transormation into data sets, their rules could be fitted into the new index and a new rule set with the new index and rules from both rule sets could be created. I cloned the current master branch and changed the +(ruleset: Ruleset) method in the Ruleset.scala class:

  def +(ruleset: Ruleset): Ruleset = {
      if (index.hashCode().equals(ruleset.index.hashCode())) {
        transform(rules.concat(ruleset.rules))
      } else {
        val mergedDataset = index.toDataset + ruleset.index.toDataset
        val mergedIndex = mergedDataset.index()
        val mergedRules = mergedIndex.tripleItemMap { implicit mapper => 
          rules.map(r => ResolvedRule.simple(r)) ++ ruleset.rules.map(r => ResolvedRule.simple(r))
        }.filter(_._2.isEmpty).map(_._1)
        new Ruleset(mergedRules, mergedIndex, parallelism, isCached)
      }
  }

and published the project locally:

sbt clean compile publishLocal

changed the dependency declaration:

libraryDependencies += "com.github.propi.rdfrules" %% "core" % "1.0.0"

and ran the script again:

sbt clean compile run
rules count from the first task: 6
rules count from the second task: 45
number of exported rules: 51
[success] Total time: 3 s, completed 20. 5. 2021 13:42:01

My Scala version:

$ scala -version
Scala code runner version 2.12.8 -- Copyright 2002-2018, LAMP/EPFL and Lightbend, Inc

attachments.zip

@propi
Copy link
Owner

propi commented Jun 14, 2021

Thank you for your recommendation. I will try to integrate it within a follow version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants