Search code examples
rdfjenatriplessansa

Finding triples based on multiple subjects (SANSA-STACK)


I have a code to find Triples using a subject,So I am using Triple's find method and supplying the necessary like this :

  import net.sansa_stack.rdf.spark.model._

  val node1 = NodeFactory.createURI("http://dbpedia.org/resource/Charles_Dickens")
  val result: RDD[graph.Triple] = triplesRdd.find(Some(node1), None, None)

But how can I find a result where I can pass multiple Subject Nodes ?

  val node1 = NodeFactory.createURI("http://dbpedia.org/resource/Charles_Dickens")
  val node2 = NodeFactory.createURI("http://dbpedia.org/resource/Henry_James")
  val nodes = List(node1, node2)

  //Here I want to pass list of Subject notes
  val result = triplesRdd.find(Some(node2),None,None)

Solution

  • try this code and check if it helps,

      val node1 = NodeFactory.createURI("http://dbpedia.org/resource/Charles_Dickens")
      val node2 = NodeFactory.createURI("http://dbpedia.org/resource/Henry_James")
      val nodes = List(node1, node2)
    
      //Just use filter instead of find ,it will create new RDD containing only items matching those provided subjects
      val result = tripleRDD.filter(triple => nodes.contains(triple.getSubject))
      result.toDF().show(1000,truncate = false)