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   * Concrete implementation of {@link org.deri.any23.extractor.Extractor.ContentExtractor}
30   * handling <a href="http://sw.deri.org/2008/07/n-quads/">N-Quads</a> format.
31   *
32   * @author Michele Mostarda (mostarda@fbk.eu)
33   */
34  public class NQuadsExtractor extends BaseRDFExtractor {
35  
36      public final static ExtractorFactory<NQuadsExtractor> factory =
37          SimpleExtractorFactory.create(
38                  "rdf-nq",
39                  null,
40                  Arrays.asList(
41                          "text/rdf+nq;q=0.1",
42                          "text/nq;q=0.1",
43                          "text/nquads;q=0.1",
44                          "text/n-quads;q=0.1"
45                  ),
46                  "example-nquads.nq",
47                  NQuadsExtractor.class
48          );
49  
50      public NQuadsExtractor(boolean verifyDataType, boolean stopAtFirstError) {
51          super(verifyDataType, stopAtFirstError);
52      }
53  
54      public NQuadsExtractor() {
55          this(false, false);
56      }
57  
58      public ExtractorDescription getDescription() {
59          return factory;
60      }
61  
62      @Override
63      protected RDFParserBase getParser(ExtractionContext extractionContext, ExtractionResult extractionResult) {
64          return RDFParserFactory.getInstance().getNQuadsParser(
65                  isVerifyDataType(), isStopAtFirstError(), extractionContext, extractionResult
66          );
67      }
68  
69  }