Add support for JSON-LD import
This commit is contained in:
parent
676d051cac
commit
42e8c86a78
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Copyright 2012, Thomas F. Morris
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are
|
||||||
|
met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above
|
||||||
|
copyright notice, this list of conditions and the following disclaimer
|
||||||
|
in the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name of Google Inc. nor the names of its
|
||||||
|
contributors may be used to endorse or promote products derived from
|
||||||
|
this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.google.refine.importers;
|
||||||
|
|
||||||
|
|
||||||
|
public class RdfJsonldTripleImporter extends RdfTripleImporter {
|
||||||
|
|
||||||
|
public RdfJsonldTripleImporter() {
|
||||||
|
super(RdfTripleImporter.Mode.JSONLD);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -62,7 +62,8 @@ public class RdfTripleImporter extends ImportingParserBase {
|
|||||||
RDFXML,
|
RDFXML,
|
||||||
NT,
|
NT,
|
||||||
N3,
|
N3,
|
||||||
TTL
|
TTL,
|
||||||
|
JSONLD
|
||||||
}
|
}
|
||||||
|
|
||||||
public RdfTripleImporter() {
|
public RdfTripleImporter() {
|
||||||
@ -88,6 +89,9 @@ public class RdfTripleImporter extends ImportingParserBase {
|
|||||||
case TTL:
|
case TTL:
|
||||||
model.read(input, null, "TTL");
|
model.read(input, null, "TTL");
|
||||||
break;
|
break;
|
||||||
|
case JSONLD:
|
||||||
|
model.read(input, null, "JSON-LD");
|
||||||
|
break;
|
||||||
case RDFXML:
|
case RDFXML:
|
||||||
model.read(input, null);
|
model.read(input, null);
|
||||||
break;
|
break;
|
||||||
|
@ -234,4 +234,42 @@ public class RdfTripleImporterTests extends ImporterTest {
|
|||||||
Assert.assertEquals(project.rows.get(0).cells.get(2).value, "mailto:fred@example.com");
|
Assert.assertEquals(project.rows.get(0).cells.get(2).value, "mailto:fred@example.com");
|
||||||
Assert.assertEquals(project.rows.get(0).cells.get(3).value, "Fred");
|
Assert.assertEquals(project.rows.get(0).cells.get(3).value, "Fred");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void canParseJsonld() throws UnsupportedEncodingException {
|
||||||
|
String sampleJsonld = "{\n "+
|
||||||
|
" \"@context\": {\n "+
|
||||||
|
" \"m\": \"http://www.example.org/meeting_organization#\",\n "+
|
||||||
|
" \"p\": \"http://www.example.org/personal_details#\",\n "+
|
||||||
|
" \"rdf\": \"http://www.w3.org/1999/02/22-rdf-syntax-ns#\",\n "+
|
||||||
|
" \"rdfs\": \"http://www.w3.org/2000/01/rdf-schema#\",\n "+
|
||||||
|
" \"xsd\": \"http://www.w3.org/2001/XMLSchema#\"\n "+
|
||||||
|
" },\n "+
|
||||||
|
" \"@id\": \"http://www.example.org/people#fred\",\n "+
|
||||||
|
" \"m:attending\": {\n "+
|
||||||
|
" \"@id\": \"http://meetings.example.com/cal#m1\"\n "+
|
||||||
|
" },\n "+
|
||||||
|
" \"p:GivenName\": \"Fred\",\n "+
|
||||||
|
" \"p:hasEmail\": {\n "+
|
||||||
|
" \"@id\": \"mailto:fred@example.com\"\n "+
|
||||||
|
" }\n "+
|
||||||
|
"}";
|
||||||
|
|
||||||
|
InputStream input = new ByteArrayInputStream(sampleJsonld.getBytes("UTF-8"));
|
||||||
|
|
||||||
|
SUT = new RdfTripleImporter(RdfTripleImporter.Mode.JSONLD);
|
||||||
|
parseOneFile(SUT, input);
|
||||||
|
|
||||||
|
Assert.assertEquals(project.columnModel.columns.size(), 4);
|
||||||
|
Assert.assertEquals(project.columnModel.columns.get(0).getName(), "subject");
|
||||||
|
Assert.assertEquals(project.columnModel.columns.get(1).getName(), "http://www.example.org/personal_details#hasEmail");
|
||||||
|
Assert.assertEquals(project.columnModel.columns.get(2).getName(), "http://www.example.org/personal_details#GivenName");
|
||||||
|
Assert.assertEquals(project.columnModel.columns.get(3).getName(), "http://www.example.org/meeting_organization#attending");
|
||||||
|
Assert.assertEquals(project.rows.size(), 1);
|
||||||
|
Assert.assertEquals(project.rows.get(0).cells.size(), 4);
|
||||||
|
Assert.assertEquals(project.rows.get(0).cells.get(0).value, "http://www.example.org/people#fred");
|
||||||
|
Assert.assertEquals(project.rows.get(0).cells.get(1).value, "mailto:fred@example.com");
|
||||||
|
Assert.assertEquals(project.rows.get(0).cells.get(2).value, "Fred");
|
||||||
|
Assert.assertEquals(project.rows.get(0).cells.get(3).value, "http://meetings.example.com/cal#m1");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,6 +220,7 @@ function registerImporting() {
|
|||||||
IM.registerFormat("binary/text/xml/xls/xlsx", "Excel files", "ExcelParserUI", new Packages.com.google.refine.importers.ExcelImporter());
|
IM.registerFormat("binary/text/xml/xls/xlsx", "Excel files", "ExcelParserUI", new Packages.com.google.refine.importers.ExcelImporter());
|
||||||
IM.registerFormat("text/xml/ods", "Open Document Format spreadsheets (.ods)", "ExcelParserUI", new Packages.com.google.refine.importers.OdsImporter());
|
IM.registerFormat("text/xml/ods", "Open Document Format spreadsheets (.ods)", "ExcelParserUI", new Packages.com.google.refine.importers.OdsImporter());
|
||||||
IM.registerFormat("text/xml/rdf", "RDF/XML files", "RdfTriplesParserUI", new Packages.com.google.refine.importers.RdfXmlTripleImporter());
|
IM.registerFormat("text/xml/rdf", "RDF/XML files", "RdfTriplesParserUI", new Packages.com.google.refine.importers.RdfXmlTripleImporter());
|
||||||
|
IM.registerFormat("text/ld+json", "JSON-LD files", "RdfTriplesParserUI", new Packages.com.google.refine.importers.RdfJsonldTripleImporter());
|
||||||
IM.registerFormat("text/json", "JSON files", "JsonParserUI", new Packages.com.google.refine.importers.JsonImporter());
|
IM.registerFormat("text/json", "JSON files", "JsonParserUI", new Packages.com.google.refine.importers.JsonImporter());
|
||||||
IM.registerFormat("text/marc", "MARC files", "XmlParserUI", new Packages.com.google.refine.importers.MarcImporter());
|
IM.registerFormat("text/marc", "MARC files", "XmlParserUI", new Packages.com.google.refine.importers.MarcImporter());
|
||||||
IM.registerFormat("text/wiki", "Wikitext", "WikitextParserUI", new Packages.com.google.refine.importers.WikitextImporter());
|
IM.registerFormat("text/wiki", "Wikitext", "WikitextParserUI", new Packages.com.google.refine.importers.WikitextImporter());
|
||||||
@ -240,6 +241,7 @@ function registerImporting() {
|
|||||||
|
|
||||||
IM.registerExtension(".json", "text/json");
|
IM.registerExtension(".json", "text/json");
|
||||||
IM.registerExtension(".js", "text/json");
|
IM.registerExtension(".js", "text/json");
|
||||||
|
IM.registerExtension(".jsonld", "text/ld+json");
|
||||||
|
|
||||||
IM.registerExtension(".xls", "binary/text/xml/xls/xlsx");
|
IM.registerExtension(".xls", "binary/text/xml/xls/xlsx");
|
||||||
IM.registerExtension(".xlsx", "binary/text/xml/xls/xlsx");
|
IM.registerExtension(".xlsx", "binary/text/xml/xls/xlsx");
|
||||||
@ -264,6 +266,7 @@ function registerImporting() {
|
|||||||
IM.registerMimeType("text/fixed-width", "text/line-based/fixed-width");
|
IM.registerMimeType("text/fixed-width", "text/line-based/fixed-width");
|
||||||
|
|
||||||
IM.registerMimeType("text/rdf+n3", "text/rdf+n3");
|
IM.registerMimeType("text/rdf+n3", "text/rdf+n3");
|
||||||
|
IM.registerMimeType("text/rdf+ttl", "text/rdf+ttl");
|
||||||
|
|
||||||
IM.registerMimeType("application/msexcel", "binary/text/xml/xls/xlsx");
|
IM.registerMimeType("application/msexcel", "binary/text/xml/xls/xlsx");
|
||||||
IM.registerMimeType("application/x-msexcel", "binary/text/xml/xls/xlsx");
|
IM.registerMimeType("application/x-msexcel", "binary/text/xml/xls/xlsx");
|
||||||
@ -280,6 +283,7 @@ function registerImporting() {
|
|||||||
IM.registerMimeType("text/json", "text/json");
|
IM.registerMimeType("text/json", "text/json");
|
||||||
|
|
||||||
IM.registerMimeType("application/rdf+xml", "text/xml/rdf");
|
IM.registerMimeType("application/rdf+xml", "text/xml/rdf");
|
||||||
|
IM.registerMimeType("application/ld+json", "text/ld+json");
|
||||||
|
|
||||||
IM.registerMimeType("application/marc", "text/marc");
|
IM.registerMimeType("application/marc", "text/marc");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user