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.ExtractionResult;
21  import org.deri.any23.extractor.ExtractorDescription;
22  import org.deri.any23.extractor.ExtractorFactory;
23  import org.deri.any23.extractor.SimpleExtractorFactory;
24  import org.openrdf.rio.helpers.RDFParserBase;
25  
26  import java.util.Arrays;
27  
28  /**
29   *
30   * Concrete implementation of {@link org.deri.any23.extractor.Extractor.ContentExtractor} able to perform the
31   * extraction on <a href="http://www.w3.org/TeamSubmission/turtle/">Turtle</a> documents.
32   *
33   */
34  public class TurtleExtractor extends BaseRDFExtractor {
35  
36      public static final ExtractorFactory<TurtleExtractor> factory =
37              SimpleExtractorFactory.create(
38                      "rdf-turtle",
39                      null,
40                      Arrays.asList(
41                              "text/rdf+n3",
42                              "text/n3",
43                              "application/n3",
44                              "application/x-turtle",
45                              "application/turtle",
46                              "text/turtle"
47                      ),
48                      "example-turtle.ttl",
49                      TurtleExtractor.class
50              );
51  
52      /**
53       * Constructor, allows to specify the validation and error handling policies.
54       *
55       * @param verifyDataType   if <code>true</code> the data types will be verified,
56       *                         if <code>false</code> will be ignored.
57       * @param stopAtFirstError if <code>true</code> the parser will stop at first parsing error,
58       *                         if <code>false</code> will ignore non blocking errors.
59       */
60      public TurtleExtractor(boolean verifyDataType, boolean stopAtFirstError) {
61          super(verifyDataType, stopAtFirstError);
62      }
63  
64      /**
65       * Default constructor, with no verification of data types and no stop at first error.
66       */
67      public TurtleExtractor() {
68          this(false, false);
69      }
70  
71      public ExtractorDescription getDescription() {
72          return factory;
73      }
74  
75      @Override
76      protected RDFParserBase getParser(ExtractionContext extractionContext, ExtractionResult extractionResult) {
77          return RDFParserFactory.getInstance().getTurtleParserInstance(
78                  isVerifyDataType(), isStopAtFirstError(), extractionContext, extractionResult
79          );
80      }
81  
82  }