bib
bib

Reputation: 1040

sparql STR error

I want to get all the instances labels (in a maven project) without the langage tag.

my query is:

Select STR( ?abstract)
 Where {
         ?s <http://dbpedia.org/ontology/abstract> ?abstract.
        }

I get the following error:

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project LOD2Walks: An exception occured while executing the Java class. Encountered " "str" "STR "" at line 1, column 9.
[ERROR] Was expecting one of:
[ERROR] <VAR1> ...
[ERROR] <VAR2> ...
[ERROR] "distinct" ...
[ERROR] "reduced" ...
[ERROR] "(" ...
[ERROR] "*" ...

PS: If i dont write str in my query, i dont get any error If I added SELECT STR(?abstract) AS ?label)... i get the following exceptions:

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project LOD2Walks: An exception occured while executing the Java class. null: NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project LOD2Walks: An exception occured while executing the Java class. null
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
        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:497)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occured while executing the Java class. null
        at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:339)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
        ... 20 more

Can someone please help me by identifying where is my error?

Thank you in advance

Upvotes: 0

Views: 100

Answers (1)

Joshua Taylor
Joshua Taylor

Reputation: 85853

Your query isn't legal syntax. You can check at sparql.org's query validator. A simplified version would be

select str(<http://example.org>) {}

which is syntactically invalid:

Encountered " "str" "str "" at line 1, column 8.
Was expecting one of:
     ...
     ...
    "distinct" ...
    "reduced" ...
    "(" ...
    "*" ...

Instead, you need to bind the expression to a variable:

select (str(<http://example.org>) as ?str) {}

The SPARQL spec is available online, and the corresponding grammar production is:

[9]   SelectClause      ::=   'SELECT' ( 'DISTINCT' | 'REDUCED' )? ( ( Var | ( '(' Expression 'AS' Var ')' ) )+ | '*' )

Even though some endpoints might accept a non-standard syntax, if you want portability you'll need to stick to the standard syntax.

Personally, I think this is a good reason for implementations to stick to the spec, except for extensions that would already keep you with that particular implementation. "Supporting" non-standard syntax just invites users to get stuck with a particular implementation when it's not actually necessary.

Upvotes: 3

Related Questions