# Create virtual graph from CSV

**URL:** <https://community.stardog.com/t/create-virtual-graph-from-csv/1525>\
**Category:** Support\
**Created:** [March 15, 2019, 2:06pm UTC](https://community.stardog.com/t/create-virtual-graph-from-csv/1525 "2019-03-15T14:06:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![R3000](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/r3000/32/358_2.png) [@R3000](https://community.stardog.com/u/R3000)\
**Post date:** [March 15, 2019, 2:06pm UTC](https://community.stardog.com/t/create-virtual-graph-from-csv/1525/1 "2019-03-15T14:06:44Z")

</div>

Based on this post [Virtual Graph CSV Import](https://community.stardog.com/t/virtual-graph-csv-import/1051) I have tried the following:

```
[… bin]$ more mapping.ttl
@prefix rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns# .
@prefix xsd: http://www.w3.org/2001/XMLSchema# .
@prefix person: http://example.com/person/ 5 .
@prefix sm: tag:stardog:api:mapping: .

person:{ID} a person:Person ;
person:title “{Title}” ;
person:firstName “{First Name}” ;
person:lastName “{Last Name}” ;
person:jobTitle “{Job Title}” ;
person:organization “{Organization}” ;
sm:map [
sm:table “Person” ;
] .
[… bin]$ more data.csv
Type,ID,Title,First Name,Last Name,Job Title,Organization
Person,121627870,Mr,Tony,McTony,Data Scientist,
Person,155342734,John,Smith,Data architect,

[… bin]$ ./stardog-admin virtual import Test2 mapping.ttl data.csv
Expected <, found 'h' [L1]

```

Do you know why am I getting this error?  
**Expected \<, found 'h' [L1]**

---

<div class="post-metadata">

**Author:** ![matthias](https://avatars.discourse-cdn.com/v4/letter/m/cdc98d/32.png) [@matthias](https://community.stardog.com/u/matthias)\
**Post date:** [March 15, 2019, 5:01pm UTC](https://community.stardog.com/t/create-virtual-graph-from-csv/1525/2 "2019-03-15T17:01:11Z")

</div>

Read here or somewhere else: [RDF 1.1 Turtle](https://www.w3.org/TR/turtle/)

Your @prefix lines should read something like

@prefix rdf: \<[http://www.w3.org/1999/02/22-rdf-syntax-ns#\](http://www.w3.org/1999/02/22-rdf-syntax-ns#%5C)\> .

In other words, you are missing the \<...\> around the IRI of the prefix.

---

<div class="post-metadata">

**Author:** ![R3000](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/r3000/32/358_2.png) [@R3000](https://community.stardog.com/u/R3000)\
**Post date:** [March 18, 2019, 1:06pm UTC](https://community.stardog.com/t/create-virtual-graph-from-csv/1525/3 "2019-03-18T13:06:39Z")

</div>

Matthias,

Thanks for your help. After adding the angle brackets and replacing the double quotes windows style to linux I have the following:

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

person:{ID} a person:Person ;
person:title "{Title}" ;
person:firstName "{First Name}" ;
person:lastName "{Last Name}" ;
person:jobTitle "{Job Title}" ;
person:organization "{Organization}" ;
sm:map [
sm:table "Person" ;

```

So no errors this time when I run:  
`[… bin]$ ./stardog-admin virtual import Test2 mapping.ttl data.csv`  
`6`

So my guess that 6 triples have been added, right? However Test2 still has zero triples for some reason.

Any idea?

Thanks,  
Radu

---

<div class="post-metadata">

**Author:** ![PaulJackson](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/pauljackson/32/243_2.png) [@PaulJackson](https://community.stardog.com/u/PaulJackson)\
**Post date:** [March 18, 2019, 2:08pm UTC](https://community.stardog.com/t/create-virtual-graph-from-csv/1525/4 "2019-03-18T14:08:49Z")

</div>

That is likely the message portion of an IndexOutOfBounds exception (the latest release gives a better error message).

This occurs if your mapping defines more fields than exist in the file. Every record must have all fields defined.

Maybe try loading just the first record to confirm that the mapping works before attempting to load all the records.

-Paul

---

<div class="post-metadata">

**Author:** ![zachary.whitley](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/zachary.whitley/32/94_2.png) [@zachary.whitley](https://community.stardog.com/u/zachary.whitley)\
**Post date:** [March 18, 2019, 3:38pm UTC](https://community.stardog.com/t/create-virtual-graph-from-csv/1525/5 "2019-03-18T15:38:58Z")

</div>

I've had it on my todo list to look into creating an icv and archetype for r2rml and to see if using the reasoner might help with mapping files.

It would also be nice to be able use Stardog for creating and hosting mapping files so you could us ICV, reasoning, StardogStudio, VCS, etc.

You can do it right now buy you'd have to do something like

```auto
$ stardog-admin virtual import myDb dept.properties <(stardog data export deptMap -g http://mymapping/dept)

```

or using curl and the graph protocol, or something similar. I should mention that you'd have to use the r2rml not sms. Anyhoo, just a thought. Someone can give it a thumbs up if they think it's a good idea or let me know why it's a really stupid idea.

---

<div class="post-metadata">

**Author:** ![R3000](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/r3000/32/358_2.png) [@R3000](https://community.stardog.com/u/R3000)\
**Post date:** [March 18, 2019, 3:43pm UTC](https://community.stardog.com/t/create-virtual-graph-from-csv/1525/6 "2019-03-18T15:43:18Z")

</div>

Yes - indeed adding a value for Organization solved the problem - thank you!

This github is also very helpful [stardog-examples/examples/cli/virtual/csv at develop · stardog-union/stardog-examples · GitHub](https://github.com/stardog-union/stardog-examples/tree/develop/examples/cli/virtual/csv)

It will help others if the tutorial [Home | Stardog Documentation Latest](https://www.stardog.com/docs/#_csv_as_virtual_graph) would include a link to the above github example

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [April 1, 2019, 3:54pm UTC](https://community.stardog.com/t/create-virtual-graph-from-csv/1525/7 "2019-04-01T15:54:37Z")

</div>

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