View Javadoc

1   /*
2    * Copyright 2008-2010 Digital Enterprise Research Institute (DERI)
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *          http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.deri.any23.extractor.rdf;
18  
19  import org.deri.any23.extractor.ExtractionContext;
20  import org.deri.any23.extractor.ExtractionException;
21  import org.deri.any23.extractor.ExtractionParameters;
22  import org.deri.any23.extractor.ExtractionResult;
23  import org.deri.any23.extractor.Extractor.ContentExtractor;
24  import org.deri.any23.extractor.ExtractorDescription;
25  import org.deri.any23.extractor.ExtractorFactory;
26  import org.deri.any23.extractor.SimpleExtractorFactory;
27  import org.openrdf.rio.RDFHandlerException;
28  import org.openrdf.rio.RDFParseException;
29  import org.openrdf.rio.RDFParser;
30  import org.openrdf.rio.helpers.RDFParserBase;
31  
32  import java.io.IOException;
33  import java.io.InputStream;
34  import java.util.Arrays;
35  
36  /**
37   * Concrete implementation of {@link org.deri.any23.extractor.Extractor.ContentExtractor}
38   * handling NTriples <a href="http://www.w3.org/2001/sw/RDFCore/ntriples/">NTriples</a> format.
39   */
40  public class NTriplesExtractor extends BaseRDFExtractor {
41  
42      public final static ExtractorFactory<NTriplesExtractor> factory =
43              SimpleExtractorFactory.create(
44                      "rdf-nt",
45                      null,
46                      Arrays.asList(
47                              "text/nt;q=0.1",
48                              "text/ntriples;q=0.1",
49                              "text/plain;q=0.1"
50                      ),
51                      "example-ntriples.nt",
52                      NTriplesExtractor.class
53              );
54  
55      public NTriplesExtractor(boolean verifyDataType, boolean stopAtFirstError) {
56          super(verifyDataType, stopAtFirstError);
57      }
58  
59      /**
60       * Default constructor, with no verification of data types and no stop at first error.
61       */
62      public NTriplesExtractor() {
63          this(false, false);
64      }
65  
66      public ExtractorDescription getDescription() {
67          return factory;
68      }
69  
70      @Override
71      protected RDFParserBase getParser(ExtractionContext extractionContext, ExtractionResult extractionResult) {
72          return RDFParserFactory.getInstance().getNTriplesParser(
73                  isVerifyDataType(), isStopAtFirstError(), extractionContext, extractionResult
74          );
75      }
76  
77  }