Import CSV file

Hi,

I am trying to create graph using csv data .
It is showing that import is successful however no data comes into the DB.
Steps I followed is as below:

  1. Created a csv file
    image

  2. Created a call.sms file

PREFIX person: <http://stardog.com/person/>
MAPPING
FROM CSV {
    "Src" : "?src"
	}
 
TO {
  ?person1 a person:Person ;
		person:name ?src.
}
WHERE {
  BIND (template("http://stardog.com/person/{src}") AS ?person1)
}
  1. Ran the import command and details is
C:\stardog\bin>stardog-admin virtual import --format sms2 call call.sms Zac.csv
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$2 (file:/C:/stardog/client/api/guice-4.0.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$2
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Import completed successfully

Hi!

The text between the braces after "CSV" is ignored. You will need to use variable names which cases matching the field headers, eg. person:name ?Src. and BIND (template("http://stardog.com/person/{Src}") AS ?person1).

Best,
Jess

1 Like

Thanks a lot Jess, It worked. Although It is given in the tutorial however i was confused then how to map csv column header with a variable name.

Now with below sms I am able to create relationship

MAPPING
FROM CSV {
   	}
 
TO {
	?person1 a person:Person ;
		person:name ?Src.
	?person2 a person:Person ;
		person:name ?Tgt.
	?person1:called ?person2.
	
}
WHERE {
  BIND (template("http://stardog.com/person/{Src}") AS ?person1)
  BIND (template("http://stardog.com/person/{Tgt}") AS ?person2)
}

Please let me know if this is good?
Also I need to associate time of the call. screenshot attached in my previous post of the same issue.
As I come from LPG background , could you please help me to design this.

You can create an IRI for the call record using the row number, eg BIND(template("my_prefix:call:{ROW_NUMBER}") as ?call). Then you can use the call to associate all related pieces of data:

?call :from ?person1 ; :to ?person2 ; :at ?date

The date strings shown in your example are not valid ISO 8601 date strings are not compatible with the xsd:dateTime type. If you would prefer to treat them as timestamps in Stardog, it will be necessary to perform some additional formatting manipulation.

Jess

Thanks Jess,

PREFIX per: <http://stardog.com/person/>
PREFIX call: <http://stardog.com/call/>
MAPPING
FROM CSV {
   	}
 
TO {
	?person1 a per:Person ;
		per:name ?Src.
	?person2 a per:Person ;
		per:name ?Tgt.
	?call call:from ?person1 ; 
		  call:to ?person2 ; 
		  call:at ?date.
	
}
WHERE {
  BIND (template("http://stardog.com/person/{Src}") AS ?person1)
  BIND (template("http://stardog.com/person/{Tgt}") AS ?person2)
  BIND(template("http://stardog.com/call/{ROW_NUMBER}") as ?call)
}

is not allowing objects related to call in the graph.
Please correct me where I am wrong

I'm not understanding the issue. What do you mean "is not allowing objects related to call in the graph"?

I mean to say that query like below

PREFIX per: <http://stardog.com/person/>
PREFIX call: <http://stardog.com/call/>
select *
where{
?s call:to ?o
}

is not giving any output
whereas below query is giving output

PREFIX per: <http://stardog.com/person/>
PREFIX call: <http://stardog.com/call/>
select *
where{
?s per:name ?o
}

I see. Pardon my mistake. This line should be:
BIND(template("http://stardog.com/call/{_ROW_NUMBER_}") as ?call)

Note the underscores in the variable name which were missing.

Thanks a lot :slight_smile:
It worked

Glad to hear! We'll get the documentation fixed.