@@ -10,9 +10,9 @@ function onexit() {
1010
1111print_usage ()
1212{
13- printf " Transforms CSV data into RDF using a SPARQL query and imports it.\n"
13+ printf " Transforms RDF data using a SPARQL query and imports it.\n"
1414 printf " \n"
15- printf " Usage: %s options\n" " $0 "
15+ printf " Usage: %s options TARGET_URI \n" " $0 "
1616 printf " \n"
1717 printf " Options:\n"
1818 printf " -f, --cert-pem-file CERT_FILE .pem file with the WebID certificate of the agent\n"
@@ -25,13 +25,9 @@ print_usage()
2525 printf " --slug STRING String that will be used as URI path segment (optional)\n"
2626 printf " \n"
2727 printf " --query-file ABS_PATH Absolute path to the text file with the SPARQL query string (optional)\n"
28- printf " --query-doc-slug STRING String that will be used as the query's URI path segment (optional)\n"
2928 printf " --graph GRAPH_URI URI of the graph (optional)\n"
30- printf " --file ABS_PATH Absolute path to the CSV file (optional)\n"
31- printf " --file-slug STRING String that will be used as the file's URI path segment (optional)\n"
32- printf " --file-doc-slug STRING String that will be used as the file document's URI path segment (optional)\n"
33- printf " --file-content-type MEDIA_TYPE Media type of the file\n"
34- printf " --import-slug STRING String that will be used as the import's URI path segment (optional)\n"
29+ printf " --rdf-file ABS_PATH Absolute path to the RDF file (optional)\n"
30+ printf " --content-type MEDIA_TYPE Media type of the file\n"
3531}
3632
3733args=()
7571 shift # past argument
7672 shift # past value
7773 ;;
78- --query-doc-slug )
79- query_doc_slug =" $2 "
74+ --rdf-file )
75+ rdf_file =" $2 "
8076 shift # past argument
8177 shift # past value
8278 ;;
83- --file)
84- file=" $2 "
85- shift # past argument
86- shift # past value
87- ;;
88- --file-slug)
89- file_slug=" $2 "
90- shift # past argument
91- shift # past value
92- ;;
93- --file-doc-slug)
94- file_doc_slug=" $2 "
95- shift # past argument
96- shift # past value
97- ;;
98- --file-content-type)
99- file_content_type=" $2 "
100- shift # past argument
101- shift # past value
102- ;;
103- --import-slug)
104- import_slug=" $2 "
79+ --content-type)
80+ content_type=" $2 "
10581 shift # past argument
10682 shift # past value
10783 ;;
11389done
11490set -- " ${args[@]} " # restore args
11591
92+ target=" $1 "
93+
11694if [ -z " $cert_pem_file " ] ; then
11795 print_usage
11896 exit 1
@@ -129,11 +107,11 @@ if [ -z "$title" ] ; then
129107 print_usage
130108 exit 1
131109fi
132- if [ -z " $file " ] ; then
110+ if [ -z " $rdf_file " ] ; then
133111 print_usage
134112 exit 1
135113fi
136- if [ -z " $file_content_type " ] ; then
114+ if [ -z " $content_type " ] ; then
137115 print_usage
138116 exit 1
139117fi
@@ -142,27 +120,6 @@ if [ -z "$proxy" ] ; then
142120 proxy=" $base "
143121fi
144122
145- # Create the imports/ container first
146- create-container.sh \
147- -b " $base " \
148- -f " $cert_pem_file " \
149- -p " $cert_password " \
150- --proxy " $proxy " \
151- --title " Imports" \
152- --parent " $base " \
153- --slug " imports"
154-
155- # Create the import item document
156- import_doc=$( create-item.sh \
157- -b " $base " \
158- -f " $cert_pem_file " \
159- -p " $cert_password " \
160- --proxy " $proxy " \
161- --title " $title " \
162- --container " ${base} imports/" \
163- --slug " $query_doc_slug "
164- )
165-
166123if [ -n " $query_file " ] ; then
167124 # Generate query ID for fragment identifier
168125 query_id=$( uuidgen | tr ' [:upper:]' ' [:lower:]' )
@@ -177,10 +134,10 @@ if [ -n "$query_file" ] ; then
177134 --title " $title " \
178135 --uri " #${query_id} " \
179136 --query-file " $query_file " \
180- " $import_doc "
137+ " $target "
181138
182139 # The query URI is the document with fragment
183- query=" ${import_doc } #${query_id} "
140+ query=" ${target } #${query_id} "
184141fi
185142
186143# Add the file to the import item
@@ -190,13 +147,13 @@ add-file.sh \
190147 -p " $cert_password " \
191148 --proxy " $proxy " \
192149 --title " $title " \
193- --file " $file " \
194- --file- content-type " $file_content_type " \
195- " $import_doc "
150+ --file " $rdf_file " \
151+ --content-type " $content_type " \
152+ " $target "
196153
197154# Calculate file URI from SHA1 hash
198- sha1sum=$( shasum -a 1 " $file " | awk ' {print $1}' )
199- file_uri =" ${base} uploads/${sha1sum} "
155+ sha1sum=$( shasum -a 1 " $rdf_file " | awk ' {print $1}' )
156+ rdf_file_uri =" ${base} uploads/${sha1sum} "
200157
201158# Generate import ID for fragment identifier
202159import_id=$( uuidgen | tr ' [:upper:]' ' [:lower:]' )
@@ -211,8 +168,8 @@ if [ -n "$query" ] ; then
211168 --title " $title " \
212169 --uri " #${import_id} " \
213170 --query " $query " \
214- --file " $file_uri " \
215- " $import_doc "
171+ --file " $rdf_file_uri " \
172+ " $target "
216173else
217174 add-rdf-import.sh \
218175 -b " $base " \
222179 --title " $title " \
223180 --uri " #${import_id} " \
224181 --graph " $graph " \
225- --file " $file_uri " \
226- " $import_doc "
182+ --file " $rdf_file_uri " \
183+ " $target "
227184fi
0 commit comments