Invalid variable error with CSV import

I am clearly missing something since this used to work ...
./stardog-admin virtual import myDb mappings.ttl Sheet2a.csv

Here is my .csv:

classname1,classname2,relevance
classname1indiv,classname2indiva,1
classname1indiv,classname2indivb,0.5

Here is my mappings.ttl:

@prefix nsp1: <http://us.com/nsp1#> .
@prefix nsp2: <http://us.com/nsp2#> .
@prefix sm: <tag:stardog:api:mapping:> .
@prefix demo: <http://us.com/demo#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

demo:{classname1}-{classname2} a demo:NewType ;
  demo:pred1 nsp1:{classname1} ;
  demo:pred2 nsp2:{classname2} ;
  sm:map [
    sm:table "Sheet2a" ;
  ] .

Here is the verbose output ...

Invalid variable: classname1
The detailed stack trace for the error is:
java.lang.IllegalArgumentException: Invalid variable: classname1
	at com.complexible.stardog.virtual.api.RDFGenerator$TemplateParser.valueProviderFor(RDFGenerator.java:119)
	at com.complexible.stardog.virtual.api.RDFGenerator$TemplateParser.insertPlaceholders(RDFGenerator.java:94)
	at com.complexible.stardog.virtual.api.RDFGenerator$TemplateParser.parseTemplate(RDFGenerator.java:129)
	at com.complexible.stardog.virtual.api.RDFGenerator$TemplateParser.access$100(RDFGenerator.java:76)
	at com.complexible.stardog.virtual.api.RDFGenerator.<init>(RDFGenerator.java:63)
	at com.complexible.stardog.virtual.api.CSVMapper.map(CSVMapper.java:141)
	at com.complexible.stardog.virtual.cli.VirtualGraphImport.execute(VirtualGraphImport.java:148)
	at com.complexible.stardog.cli.impl.ConnectionCommand.call(ConnectionCommand.java:70)
	at com.complexible.stardog.cli.CLIBase.execute(CLIBase.java:55)
	at com.complexible.stardog.cli.admin.CLI.main(CLI.java:187)

Nothing is in the log. This happened on Stardog 6.1.3 and 6.2.1.

Andrea

You haven't set csv.header=false, have you?

Jess, I didn't set csv.header at all. I just tried creating a properties file with csv.header=true and the error remains.

Andrea

What version? It's working for me:
C:@git\stardog\dist>type Sheet2a.csv
classname1,classname2,relevance
classname1indiv,classname2indiva,1
classname1indiv,classname2indivb,0.5

C:@git\stardog\dist>type mappings.ttl
@prefix nsp1: <http://us.com/nsp1#> .
@prefix nsp2: <http://us.com/nsp2#> .
@prefix sm: tag:stardog:api:mapping: .
@prefix demo: <http://us.com/demo#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

demo:{classname1}-{classname2} a demo:NewType ;
demo:pred1 nsp1:{classname1} ;
demo:pred2 nsp2:{classname2} ;
sm:map [
sm:table "Sheet2a" ;
] .

C:@git\stardog\dist>sa virtual import foo mappings.ttl Sheet2a.csv
Successfully imported 6 triples into foo

I tried 6.1.3 and the latest release.

Andrea

I am running on a Mac.

I changed my spreadsheet output to tab-delimited and modified it and my mappings.ttl file using TextEdit (versus TextMate). Now, things are working.

I am not sure why those changes made a difference ... but they did.

Andrea

I'm glad it's working.

I just inspected the code. There's nothing that checks the OS type. The default separator is comma. The only way to change it is to set a csv.separator property. I see you're not using a property file on the command line. I am at a loss for an explanation.

I will add some code that improves the error message, indicating what the available columns are. In this case it would have indicated a single column name "classname1,classname2,relevance", which might have clued us into the delimiter issue.

-Paul

I think that it was more about some non-printable characters that were inserted by Excel's .csv output and/or kept by TextMate, rather than the actual data.

When I moved to Excel tab-delimited (which creates a .txt file) and then edited with TextEdit, the world was good. In that case, I did add a properties file.

That makes sense. Given that the field that Stardog was complaining about was the first column, it could have been a byte order marker. I'll take a look to see that we correctly handle those.

Thanks.

-Paul

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.