Search in sources :

Example 1 with Param

use of org.apache.tika.config.Param in project tika by apache.

the class AnnotationUtilsTest method testParamValueInheritance.

@Test
public void testParamValueInheritance() {
    class Bean {

        @Field(required = true)
        CharSequence field;
    }
    Bean parser = new Bean();
    Map<String, Param> params = new HashMap<>();
    try {
        String val = "someval";
        params.put("field", new Param<String>("field", String.class, val));
        AnnotationUtils.assignFieldParams(parser, params);
        Assert.assertEquals(val, parser.field);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("Exception not expected, string is assignable to CharSequence");
    }
    try {
        Date val = new Date();
        params.put("field", new Param<Date>("field", Date.class, val));
        AnnotationUtils.assignFieldParams(parser, params);
        Assert.fail("Exception expected, Date is not assignable to CharSequence.");
    } catch (TikaConfigException e) {
    //expected
    }
}
Also used : HashMap(java.util.HashMap) Param(org.apache.tika.config.Param) TikaConfigException(org.apache.tika.exception.TikaConfigException) TikaConfigException(org.apache.tika.exception.TikaConfigException) Date(java.util.Date) Test(org.junit.Test)

Example 2 with Param

use of org.apache.tika.config.Param in project tika by apache.

the class TensorflowVideoRecParserTest method recognise.

@Test
public void recognise() throws Exception {
    TensorflowRESTVideoRecogniser recogniser = new TensorflowRESTVideoRecogniser();
    recogniser.initialize(new HashMap<String, Param>());
    try (InputStream stream = getClass().getClassLoader().getResourceAsStream("test-documents/testVideoMp4.mp4")) {
        List<RecognisedObject> objects = recogniser.recognise(stream, new DefaultHandler(), new Metadata(), new ParseContext());
        Assert.assertTrue(objects.size() > 0);
        Set<String> objectLabels = new HashSet<>();
        for (RecognisedObject object : objects) {
            objectLabels.add(object.getLabel());
        }
        Assert.assertTrue(objectLabels.size() > 0);
    }
}
Also used : InputStream(java.io.InputStream) Param(org.apache.tika.config.Param) Metadata(org.apache.tika.metadata.Metadata) ParseContext(org.apache.tika.parser.ParseContext) RecognisedObject(org.apache.tika.parser.recognition.RecognisedObject) DefaultHandler(org.xml.sax.helpers.DefaultHandler) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with Param

use of org.apache.tika.config.Param in project tika by apache.

the class TensorflowImageRecParserTest method recognise.

@Test
public void recognise() throws Exception {
    TensorflowImageRecParser recogniser = new TensorflowImageRecParser();
    recogniser.initialize(new HashMap<String, Param>());
    try (InputStream stream = getClass().getClassLoader().getResourceAsStream("test-documents/testJPEG.jpg")) {
        List<RecognisedObject> objects = recogniser.recognise(stream, new DefaultHandler(), new Metadata(), new ParseContext());
        Assert.assertTrue(5 == objects.size());
        Set<String> objectLabels = new HashSet<>();
        for (RecognisedObject object : objects) {
            objectLabels.add(object.getLabel());
        }
        System.out.println(objectLabels);
        String[] expected = { "Egyptian cat", "tabby, tabby cat" };
        for (String label : expected) {
            Assert.assertTrue(label + " is expected", objectLabels.contains(label));
        }
    }
}
Also used : InputStream(java.io.InputStream) Metadata(org.apache.tika.metadata.Metadata) RecognisedObject(org.apache.tika.parser.recognition.RecognisedObject) DefaultHandler(org.xml.sax.helpers.DefaultHandler) Param(org.apache.tika.config.Param) ParseContext(org.apache.tika.parser.ParseContext) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Param (org.apache.tika.config.Param)3 Test (org.junit.Test)3 InputStream (java.io.InputStream)2 HashSet (java.util.HashSet)2 Metadata (org.apache.tika.metadata.Metadata)2 ParseContext (org.apache.tika.parser.ParseContext)2 RecognisedObject (org.apache.tika.parser.recognition.RecognisedObject)2 DefaultHandler (org.xml.sax.helpers.DefaultHandler)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 TikaConfigException (org.apache.tika.exception.TikaConfigException)1