Skip to content

Commit

Permalink
Fix #339
Browse files Browse the repository at this point in the history
  • Loading branch information
enridaga committed Feb 3, 2023
1 parent 91291b7 commit a4e9351
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.riot.Lang;
import org.apache.jena.riot.RDFDataMgr;
import org.apache.jena.riot.RDFParserRegistry;
import org.apache.jena.riot.ReaderRIOTFactory;
import org.apache.jena.sparql.core.ResultBinding;
import org.apache.jena.sparql.core.Var;
import org.apache.jena.sparql.engine.binding.Binding;
Expand Down Expand Up @@ -78,6 +80,10 @@ public class SPARQLAnything {
private static Long duration = null;

private static void initSPARQLAnythingEngine() throws TriplifierRegisterException {
// Register the JSON-LD parser factory for extension .json
ReaderRIOTFactory parserFactoryJsonLD = new RiotUtils.ReaderRIOTFactoryJSONLD();
RDFParserRegistry.registerLangTriples(RiotUtils.JSON, parserFactoryJsonLD);
// Setup FX executor
QC.setFactory(ARQ.getContext(), FacadeX.ExecutorFactory);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,17 @@
package com.github.sparqlanything.cli;

import org.apache.commons.io.IOUtils;
import org.apache.jena.atlas.lib.InternalErrorException;
import org.apache.jena.riot.Lang;
import org.apache.jena.riot.LangBuilder;
import org.apache.jena.riot.RDFParserRegistry;
import org.apache.jena.riot.ReaderRIOT;
import org.apache.jena.riot.ReaderRIOTFactory;
import org.apache.jena.riot.lang.JsonLDReader;
import org.apache.jena.riot.system.ParserProfile;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

public class JsonldTest {
public static final Logger L = LoggerFactory.getLogger(JsonldTest.class);
public class Issue339Test {
public static final Logger L = LoggerFactory.getLogger(Issue339Test.class);

static class ReaderRIOTFactoryJSONLD implements ReaderRIOTFactory {
@Override
public ReaderRIOT create(Lang language, ParserProfile profile) {
if ( !buildJSONLang().equals(language) )
throw new InternalErrorException("Attempt to parse " + language + " as JSON-LD");
return new JsonLDReader(language, profile, profile.getErrorHandler());
}
}

static Lang buildJSONLang(){
Lang JSON = LangBuilder.create("JSON", "application/ld+json")
.addAltNames("JSON")
.addFileExtensions("json")
.build();
return JSON;
}

// Strategy to fix issue #339
@Test
public void test() throws Exception {
ReaderRIOTFactory parserFactoryJsonLD = new ReaderRIOTFactoryJSONLD();
RDFParserRegistry.registerLangTriples(buildJSONLang(), parserFactoryJsonLD);
String q = getClass().getClassLoader().getResource("./JsonldTest.sparql").toString();
File loadSource = new File(getClass().getClassLoader().getResource("./JsonldTest.json").toURI());
L.info("{}", loadSource.exists());
Expand Down

0 comments on commit a4e9351

Please sign in to comment.