You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@any23.apache.org by Michele Mostarda <mi...@gmail.com> on 2015/04/03 10:13:04 UTC
Re: Any23 class constructor
Hi Murick,
it seems it doesn't recognize the file mimetype (it tries to parse it as
RDF-NT instead than JSONLD).
Try to rename the file using jsonld extension:
File myFile = new File(“input/file.jsonld.");
Best
Michele
On 3 April 2015 at 03:09, Murick <mu...@gmail.com> wrote:
> Hi Michele,
> Thank you for recommendations. It helped a lot! Instead of manually
> attaching .jar libraries, I started a Java maven project from the scratch.
> I apologize for slow response. Everything was working fine until I tried to
> convert JSONLD to N-Triples. I got the following error:
>
>
> ExtractionContext(urn:x-any23:rdf-nt:root-extraction-result-id:file:/Users/murick/Development/Eclipse/RDF%20Converter/input/file_jsonld.txt)
> Errors {
> FATAL: 'Expected '<' or '_', found: {' (1,-1)
> }
> ------------ END Exception context ------------
>
> *code*
>
> File myFile = new File(“input/file_jsonld.txt");
> Any23 runner = new Any23();
>
> DocumentSource source = new FileDocumentSource(myFile);
> ByteArrayOutputStream out = new ByteArrayOutputStream();
> TripleHandler writer = new NTriplesWriter(out);
> try
> {
> runner.extract(source, writer); //HERE OCCURS ERROR
> }
> finally
> {
> writer.close();
> }
> System.out.println(out.toString("UTF-8"));
>
>
> *input file contents*
>
> {
> "@context": {
> "name": "http://xmlns.com/foaf/0.1/name",
> "homepage": {
> "@id": "http://xmlns.com/foaf/0.1/workplaceHomepage",
> "@type": "@id"
> },
> "Person": "http://xmlns.com/foaf/0.1/Person"
> },
> "@id": "http://me.markus-lanthaler.com",
> "@type": "Person",
> "name": "Markus Lanthaler",
> "homepage": "http://www.tugraz.at/"
> }
>
>
> *desired output*
>
> <http://me.markus-lanthaler.com> <
> http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <
> http://xmlns.com/foaf/0.1/Person> .
> <http://me.markus-lanthaler.com> <http://xmlns.com/foaf/0.1/name> "Markus
> Lanthaler"^^<http://www.w3.org/2001/XMLSchema#string> .
> <http://me.markus-lanthaler.com> <
> http://xmlns.com/foaf/0.1/workplaceHomepage> <http://www.tugraz.at/> .
>
>
>
> However, the reverse process (N-Triples —> JSONLD) is working fine. Thank
> you for your help!
>
>
--
Michele Mostarda
Senior Software Engineer
skype: michele.mostarda
twitter: micmos
mail: me@michelemostarda.com
site: http://michelemostarda.it
Re: Any23 class constructor
Posted by Michele Mostarda <mi...@gmail.com>.
Dear Murick,
in line 4
final Any23 runner = new Any23(modifiableConf,"rdf-nt");
you're declaring an Any23 instance wich suppors only RDF Ntriples extractor.
You should instead specify the json-ld extractor if you consider to process
JSONLD only or even better activate all extractors simply specifying
nothing like:
final Any23 runner = new Any23(modifiableConf);
Best
Michele
On 8 April 2015 at 03:55, Murick <mu...@gmail.com> wrote:
> Hi Michele,
> Sorry for bothering you with questions, but I am stuck in the
> JSONLD-N-Triples conversion. As you recommended, I changed an input file
> extension to .jsonld. However, the file content doesn’t get converted.
> Here’s the code fragment. Thank you in advance.
>
>
> final ModifiableConfiguration modifiableConf =
> DefaultConfiguration.copy();
> final ExtractionParameters extractionParameters =
> ExtractionParameters.getDefault();
> extractionParameters.setFlag("any23.extraction.metadata.timesize",
> false); //REMOVE METADATA EXTRACTION
> final Any23 runner = new Any23(modifiableConf,"rdf-nt");
>
>
> File myFile = new File(“input/myfile.jsonld”);
> DocumentSource source = new FileDocumentSource(myFile);
> ByteArrayOutputStream out = new ByteArrayOutputStream();
> final TripleHandler writer = new NTriplesWriter(out);
>
> try
> {
> runner.extract(extractionParameters, source, writer);
> }
> finally
> {
> writer.close();
> }
> System.out.println(out.toString("UTF-8"));
>
>
> Best Regards,
> Imran Mammadli
>
>
>
>
--
Michele Mostarda
Senior Software Engineer
skype: michele.mostarda
twitter: micmos
mail: me@michelemostarda.com
site: http://michelemostarda.it
Re: Any23 class constructor
Posted by Murick <mu...@gmail.com>.
Hi Michele,
Sorry for bothering you with questions, but I am stuck in the JSONLD-N-Triples conversion. As you recommended, I changed an input file extension to .jsonld. However, the file content doesn’t get converted. Here’s the code fragment. Thank you in advance.
final ModifiableConfiguration modifiableConf = DefaultConfiguration.copy();
final ExtractionParameters extractionParameters = ExtractionParameters.getDefault();
extractionParameters.setFlag("any23.extraction.metadata.timesize", false); //REMOVE METADATA EXTRACTION
final Any23 runner = new Any23(modifiableConf,"rdf-nt");
File myFile = new File(“input/myfile.jsonld”);
DocumentSource source = new FileDocumentSource(myFile);
ByteArrayOutputStream out = new ByteArrayOutputStream();
final TripleHandler writer = new NTriplesWriter(out);
try
{
runner.extract(extractionParameters, source, writer);
}
finally
{
writer.close();
}
System.out.println(out.toString("UTF-8"));
Best Regards,
Imran Mammadli