ANY23-416 correct supported mimetypes in extractor factories master
authorHans <firedrake93@gmail.com>
Fri, 23 Nov 2018 01:08:22 +0000 (19:08 -0600)
committerHans <firedrake93@gmail.com>
Fri, 23 Nov 2018 01:08:22 +0000 (19:08 -0600)
core/src/main/java/org/apache/any23/extractor/rdf/NTriplesExtractorFactory.java
core/src/main/java/org/apache/any23/extractor/rdf/TurtleExtractorFactory.java
core/src/main/java/org/apache/any23/extractor/rdfa/RDFa11ExtractorFactory.java
core/src/test/java/org/apache/any23/extractor/ExtractionAPITest.java

index 8a886f5..bdfb64a 100644 (file)
@@ -42,6 +42,7 @@ public class NTriplesExtractorFactory extends SimpleExtractorFactory<NTriplesExt
                 NTriplesExtractorFactory.NAME, 
                 NTriplesExtractorFactory.PREFIXES,
                 Arrays.asList(
+                        "application/n-triples;q=0.1",
                         "text/nt;q=0.1",
                         "text/ntriples;q=0.1",
                         "text/plain;q=0.1"
index 204c2f1..6e38a08 100644 (file)
@@ -42,12 +42,12 @@ public class TurtleExtractorFactory extends SimpleExtractorFactory<TurtleExtract
                 TurtleExtractorFactory.NAME, 
                 TurtleExtractorFactory.PREFIXES,
                 Arrays.asList(
+                        "text/turtle",
                         "text/rdf+n3",
                         "text/n3",
                         "application/n3",
                         "application/x-turtle",
-                        "application/turtle",
-                        "text/turtle"
+                        "application/turtle"
                 ),
                 "example-turtle.ttl");
     }
index db2f9a0..df28824 100644 (file)
@@ -41,7 +41,7 @@ public class RDFa11ExtractorFactory extends SimpleExtractorFactory<RDFa11Extract
         super(
                 RDFa11ExtractorFactory.NAME, 
                 RDFa11ExtractorFactory.PREFIXES,
-                Arrays.asList("text/html;q=0.3", "application/xhtml+xml;q=0.3"),
+                Arrays.asList("application/xhtml+xml;q=0.3", "application/html;q=0.3", "text/html;q=0.3"),
                 "example-rdfa11.html");
     }
 
index 3e1dc73..0b50cf4 100644 (file)
 
 package org.apache.any23.extractor;
 
+import org.apache.any23.extractor.rdf.JSONLDExtractorFactory;
+import org.apache.any23.extractor.rdf.NQuadsExtractorFactory;
+import org.apache.any23.extractor.rdf.NTriplesExtractorFactory;
+import org.apache.any23.extractor.rdf.RDFXMLExtractorFactory;
+import org.apache.any23.extractor.rdf.TriXExtractorFactory;
+import org.apache.any23.extractor.rdf.TurtleExtractorFactory;
+import org.apache.any23.extractor.rdfa.RDFa11ExtractorFactory;
+import org.apache.any23.mime.MIMEType;
+import org.eclipse.rdf4j.rio.RDFFormat;
 import org.junit.Assert;
 import org.apache.any23.extractor.example.ExampleExtractor;
 import org.apache.any23.rdf.RDFUtils;
@@ -24,6 +33,9 @@ import org.apache.any23.writer.CountingTripleHandler;
 import org.junit.Test;
 import org.eclipse.rdf4j.model.IRI;
 
+import java.util.List;
+import java.util.stream.Collectors;
+
 /**
  * Tests the <i>extraction</i> scenario.
  */
@@ -42,5 +54,33 @@ public class ExtractionAPITest {
         writer.close();
         Assert.assertEquals(1, out.getCount());
     }
+
+    private static void test(ExtractorFactory<?> factory, RDFFormat... formats) {
+        List<String> mimetypes = factory.getSupportedMIMETypes().stream()
+                .map(MIMEType::getFullType).collect(Collectors.toList());
+
+        Assert.assertEquals(formats[0].getDefaultMIMEType(), mimetypes.get(0));
+
+        for (RDFFormat format : formats) {
+            for (String mimeType : format.getMIMETypes()) {
+                if (mimeType.endsWith("/xml")) {
+                    //TODO: xml mimetypes are commented out in RDFXML extractor. Why?
+                    continue;
+                }
+                Assert.assertTrue(mimeType, mimetypes.contains(mimeType));
+            }
+        }
+    }
+
+    @Test
+    public void testMimetypes() {
+        test(new JSONLDExtractorFactory(), RDFFormat.JSONLD);
+        test(new NTriplesExtractorFactory(), RDFFormat.NTRIPLES);
+        test(new NQuadsExtractorFactory(), RDFFormat.NQUADS);
+        test(new TurtleExtractorFactory(), RDFFormat.TURTLE, RDFFormat.N3);
+        test(new RDFXMLExtractorFactory(), RDFFormat.RDFXML);
+        test(new TriXExtractorFactory(), RDFFormat.TRIX);
+        test(new RDFa11ExtractorFactory(), RDFFormat.RDFA);
+    }
     
 }