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

Beginner #292

Open
Maatary opened this issue Aug 11, 2015 · 21 comments
Open

Beginner #292

Maatary opened this issue Aug 11, 2015 · 21 comments

Comments

@Maatary
Copy link
Contributor

Maatary commented Aug 11, 2015

Hi,

I am looking to add Banana-rdf to my project however i am a little puzzled as to how to proceed.

Could you please clarify the following point for me:

1 - Banana-rdf is not available as artifacts online such as on bintray or maven central, etc....

2 - You have to build and publish all the artifact yourself.

3 - After which you have to add the artifact to your project. In that regard, what artifact are required in case you just want to have a sparql engine, to query some external sparql endpoint.

4 - Why isn't it possible to simply import things instead of creating a full class and extending it with module like RDFmodule before you can operate on things. I don't understand that logic. It sounds like you have to create your own RDFlib by composing the generic things all the time? AM i right ?

@antonkulaga
Copy link
Contributor

Banana-rdf is published, just search for it at maven central

@Maatary
Copy link
Contributor Author

Maatary commented Aug 11, 2015

Error:Error while importing SBT project:
...
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
at sbt.std.Transform$$anon$4.work(System.scala:63)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
at sbt.Execute.work(Execute.scala:235)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
[error] sbt.ResolveException: unresolved dependency: org.w3#rdf_jvm_2.11;0.7: not found
[error] unresolved dependency: org.w3#ntriples_jvm_2.11;0.7: not found
[error] Use 'last' for the full log.

See complete log in /Users/maatary/Library/Logs/IntelliJIdea14/sbt.last.log

@Maatary
Copy link
Contributor Author

Maatary commented Aug 11, 2015

I have this weird error with sbt

@antonkulaga
Copy link
Contributor

. I don't understand that logic. It sounds like you have to create your own RDFlib by composing the generic things all the time? AM i right ?

You are not. The example with Sesame was given just to explain how banana-rdf works (BTW I updated it a bit https://github.com/banana-rdf/banana-rdf/wiki/Core-concepts )

@antonkulaga
Copy link
Contributor

@Maatary the documentaion is a bit outdated, we are at 0.8.x series now. Please, use

libraryDependencies += "org.w3" %% "banana-jena" % "0.8.1"

in case of jena

@bblfish
Copy link
Member

bblfish commented Aug 12, 2015

@antonkulaga that should be on the front page of github README. Someone should propose a pull request for that. Also there should be a pointer to the maven repo, so that people can see what other things were available.

@antonkulaga
Copy link
Contributor

@bblfish what do you think about cleaning README and leaving there only a link to wiki? Documentation in several places (readme and wiki) only leads to confusion (IMHO).

@Maatary
Copy link
Contributor Author

Maatary commented Aug 12, 2015

@antonkulaga please help a bit further here and i will also try by the same occasion to explain what i meant.

I want to perform some sparql query in my code. I pick Jena as the underlying engine.

If i follow the test suite as it is recommended in the doc for now, I get something like this:

trait SparqlEngineTesterTrait [Rdf <: RDF, M[+_], A] extends BeforeAndAfterAll { self: Suite =>
  val store: A
  val reader: RDFReader[Rdf, Try, RDFXML]
  implicit val ops: RDFOps[Rdf]
  implicit val graphStore: GraphStore[Rdf, M, A]
  implicit val monad:  Monad[M]
  implicit val comonad: Comonad[M]

  val lifecycle: Lifecycle[Rdf, A]

followed by

class SparqlEngineTest[Rdf <: RDF, A](
  val store: A)(implicit
  val reader: RDFReader[Rdf, Try, RDFXML],
  val ops: RDFOps[Rdf],
  val comonad: scalaz.Comonad[scala.util.Try],
  val monad: scalaz.Monad[scala.util.Try],
  val sparqlOps: SparqlOps[Rdf],
  val graphStore: GraphStore[Rdf, Try, A],
  val sparqlEngine: SparqlEngine[Rdf, Try, A],
  val lifecycle: Lifecycle[Rdf, A]
) extends WordSpec with SparqlEngineTesterTrait[Rdf, Try, A] with Matchers with BeforeAndAfterAll with TryValues {

I think this is very complicate and does not help to quickly grasp how to proceed. It also differs a little from the online guide about Sparql Usage (which is easier to understand). In the end i don't know which one to use:

trait SPARQLExampleDependencies
  extends RDFModule
  with RDFOpsModule
  with SparqlOpsModule
  with SparqlHttpModule

trait SPARQLExample extends SPARQLExampleDependencies { self =>

  import ops._
  import sparqlOps._
  import sparqlHttp.sparqlEngineSyntax._
import org.w3.banana.jena.JenaModule

object SPARQLExampleWithJena extends SPARQLExample with JenaModule

What i meant originally, is that, if you want to you banana-rdf, you can't just import something in a class, you have to creating that binding between an the generic abstraction and an implementation.

Is there just a simpler form ?

@antonkulaga
Copy link
Contributor

@Maatary could you, please, use

//markdown for your scala code? 

when you quote code samples?

@Maatary
Copy link
Contributor Author

Maatary commented Aug 12, 2015

Here is what i did and can't get it to work:

import java.net.URL

import org.w3.banana.{SparqlHttpModule, SparqlOpsModule, RDFOpsModule, RDFModule}

/**
 * Created by Daniel Maatari Okouya on 8/12/15.
 *
 */

trait SPARQLExampleDependencies
  extends RDFModule
  with RDFOpsModule
  with SparqlOpsModule
  with SparqlHttpModule

trait SPARQLExample extends SPARQLExampleDependencies { self =>

  import ops._
  import sparqlOps._
  import sparqlHttp.sparqlEngineSyntax._

  def main(args: Array[String]): Unit = {

    /* gets a SparqlEngine out of a Sparql endpoint */

    val endpoint = new URL("http://dbpedia.org/sparql/")

    /* creates a Sparql Select query */

    val query = parseSelect("""
PREFIX ont: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?language WHERE {
 ?language a ont:ProgrammingLanguage .
 ?language ont:influencedBy ?other .
 ?other ont:influencedBy ?language .
} LIMIT 100
                            """).get

    /* executes the query */

    val answers: Rdf#Solutions = endpoint.executeSelect(query).get

    /* iterate through the solutions */

    val languages: Iterator[Rdf#URI] = answers.iterator map { row =>
      /* row is an Rdf#Solution, we can get an Rdf#Node from the variable name */
      /* both the #Rdf#Node projection and the transformation to Rdf#URI can fail in the Try type, hense the flatMap */
      row("language").get.as[Rdf#URI].get
    }

    println(languages.to[List])
  }

}

object SparqlService extends App {

  import org.w3.banana.jena.JenaModule

  object SPARQLExampleWithJena extends SPARQLExample with JenaModule

  SPARQLExampleWithJena.main(null)

}

I get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:455)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:367)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.apache.xerces.parsers.AbstractDOMParser.startDocument(Unknown Source)
    at org.apache.xerces.impl.dtd.XMLDTDValidator.startDocument(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentScannerImpl.startEntity(Unknown Source)
    at org.apache.xerces.impl.XMLVersionDetector.startDocumentParsing(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
    at sun.util.xml.PlatformXmlPropertiesProvider.getLoadingDoc(PlatformXmlPropertiesProvider.java:106)
    at sun.util.xml.PlatformXmlPropertiesProvider.load(PlatformXmlPropertiesProvider.java:78)
    at java.util.Properties$XmlSupport.load(Properties.java:1201)
    at java.util.Properties.loadFromXML(Properties.java:881)
    at com.hp.hpl.jena.util.Metadata.read(Metadata.java:76)
    at com.hp.hpl.jena.util.Metadata.addMetadata(Metadata.java:54)
    at com.hp.hpl.jena.util.Metadata.<init>(Metadata.java:48)
    at com.hp.hpl.jena.JenaRuntime.<clinit>(JenaRuntime.java:34)
    at com.hp.hpl.jena.rdf.model.impl.RDFReaderFImpl.reset(RDFReaderFImpl.java:81)
    at com.hp.hpl.jena.rdf.model.impl.RDFReaderFImpl.<clinit>(RDFReaderFImpl.java:74)
    at com.hp.hpl.jena.rdf.model.impl.ModelCom.<clinit>(ModelCom.java:54)
    at com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel(ModelFactory.java:114)
    at org.w3.banana.jena.util.QuerySolution.<init>(QuerySolution.scala:13)
    at org.w3.banana.jena.JenaGraphSparqlEngine.<init>(JenaGraphSparqlEngine.scala:15)
    at org.w3.banana.jena.JenaGraphSparqlEngine$.apply(JenaGraphSparqlEngine.scala:44)
    at org.w3.banana.jena.JenaModule$class.$init$(JenaModule.scala:38)
    at SparqlService$SPARQLExampleWithJena$.<init>(SparqlService.scala:60)
    at SparqlService$SPARQLExampleWithJena$.<clinit>(SparqlService.scala)
    at SparqlService$.delayedEndpoint$SparqlService$1(SparqlService.scala:62)
    at SparqlService$delayedInit$body.apply(SparqlService.scala:56)
    at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at scala.App$$anonfun$main$1.apply(App.scala:76)
    at scala.App$$anonfun$main$1.apply(App.scala:76)
    at scala.collection.immutable.List.foreach(List.scala:381)
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
    at scala.App$class.main(App.scala:76)
    at SparqlService$.main(SparqlService.scala:56)
    at SparqlService.main(SparqlService.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.lang.ClassNotFoundException: org.w3c.dom.ElementTraversal
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 55 more

@Maatary
Copy link
Contributor Author

Maatary commented Aug 12, 2015

I have been able to run the example in itself. The example situated in the misc folder for the sparqlengine usage, but from within the banana-rdf project.

However,

what i want is to be able to modularize my code such that to use it out of your example, but it is not crystal clear to me how should i achieve it.

Beside when i copy paste the example from mist to my project i get the error above. In other, without event the slight modification that i introduce.

Here is my dependency declaration in my build:

"org.w3" %% "banana-jena" % "0.8.1"

@Maatary
Copy link
Contributor Author

Maatary commented Aug 12, 2015

I'm using JDK 8, scala 2.11.x
I can't seem to figure out: java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal

@Maatary
Copy link
Contributor Author

Maatary commented Aug 12, 2015

I solved my problem by forcing this:

dependencyOverrides += "xml-apis" % "xml-apis" % "1.4.01"

However my original question about modularizing stuff still remain. I will try to follow the example and modularize as i can.

The one from the test suites sounds just too complicate. (I'm talking about instantiating the rdf library not the code inside the examples.)

@Maatary
Copy link
Contributor Author

Maatary commented Aug 12, 2015

In term of modularization what i want is to bring in scope a jena-banana-rdf. Then use it in my class.

Your example hard code things in the class that construct the binder. I don't want to do that.

Here is what i tried in my scala workshit:

import java.net.URL

import org.w3.banana.jena.JenaModule
import org.w3.banana.{SparqlHttpModule, SparqlOpsModule, RDFOpsModule, RDFModule}

object SparqlService extends RDFModule with RDFOpsModule with SparqlOpsModule
with SparqlHttpModule with JenaModule

import SparqlService._

import SparqlService.sparqlOps

import SparqlService.sparqlOps._
import SparqlService.sparqlHttp.sparqlEngineSyntax._
import SparqlService.ops._

val endpoint = new URL("http://dbpedia.org/sparql/")

val query = parseSelect("""
PREFIX ont: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?language WHERE {
 ?language a ont:ProgrammingLanguage .
 ?language ont:influencedBy ?other .
 ?other ont:influencedBy ?language .
} LIMIT 100
                        """).get

query.toString

val answers: Rdf#Solutions = endpoint.executeSelect(query).get
/* iterate through the solutions */
val languages: Iterator[Rdf#URI] = answers.iterator map { row =>
  /* row is an Rdf#Solution, we can get an Rdf#Node from the variable name */
  /* both the #Rdf#Node projection and the transformation to Rdf#URI can fail in the Try type, hense the flatMap */
  row("language").get.as[Rdf#URI].get
}

println(languages.to[List])

However i get the following error:

Error:(35, 26) could not find implicit value for parameter fromPG: org.w3.banana.binder.FromPG[org.w3.banana.jena.Jena,com.hp.hpl.jena.graph.Node_URI]
  row("language").get.as[Rdf#URI].get
                        ^

I thought i had imported all the riqured implicit at that point. What am i Missing ?

@Maatary Maatary closed this as completed Aug 12, 2015
@Maatary Maatary reopened this Aug 12, 2015
@antonkulaga
Copy link
Contributor

@Maatary actually extending your class from modules is not mandatory, it is possible to work in banana-rdf just by resolving operation (RDFOps, SparqlOps, etc.) classes from Rdf<:RDF type. The examples that are in wiki are old. I think it is possible to provide simpler examples but I am simply very busy this week and do not have time for docs =(

P.S. By the way, you can have scala syntax highlightning for your scala code:

println("it syntax highlighting works!")
println("it syntax highlighting works!")

P.P.S. I also added you to banana-rdf gitter channel

@Maatary
Copy link
Contributor Author

Maatary commented Aug 12, 2015

Thank you, i will write on the channel to see if anybody can help with what you say.

Meanwhile, any idea what import i am missing here maybe ?

@bblfish
Copy link
Member

bblfish commented Aug 12, 2015

I'd go for the minimal change to the README for the moment.

@Maatary
Copy link
Contributor Author

Maatary commented Aug 13, 2015

is there a way to do a basic http authentication with the sparql engine ?

@bblfish
Copy link
Member

bblfish commented Aug 13, 2015

@Maatary that last question looks like it should be in a different issue.

@Maatary
Copy link
Contributor Author

Maatary commented Aug 13, 2015

indeed

@antonkulaga
Copy link
Contributor

I'd go for the minimal change to the README for the moment.

@bblfish I've made #295 PR to README

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

3 participants