1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 *9 * http://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17package org.apache.any23.openie;
1819import java.io.File;
20import java.io.FileOutputStream;
21import java.io.IOException;
2223import org.apache.any23.extractor.ExtractionContext;
24import org.apache.any23.extractor.ExtractionException;
25import org.apache.any23.extractor.ExtractionParameters;
26import org.apache.any23.extractor.ExtractionResult;
27import org.apache.any23.extractor.ExtractionResultImpl;
28import org.apache.any23.plugin.extractor.openie.OpenIEExtractor;
29import org.apache.any23.rdf.RDFUtils;
30import org.apache.any23.util.StreamUtils;
31import org.apache.any23.writer.RDFXMLWriter;
32import org.apache.any23.writer.TripleHandler;
33import org.apache.any23.writer.TripleHandlerException;
34import org.eclipse.rdf4j.model.IRI;
35import org.junit.After;
36import org.junit.Before;
37import org.junit.Test;
38import org.slf4j.Logger;
39import org.slf4j.LoggerFactory;
4041/**42 * @author lewismc43 *44 */45publicclassOpenIEExtractorTest {
4647privatestaticfinal Logger logger = LoggerFactory.getLogger(OpenIEExtractorTest.class);
4849private OpenIEExtractor extractor;
5051 @Before
52publicvoid setUp() throws Exception {
53 extractor = new OpenIEExtractor();
54 }
5556 @After
57publicvoid tearDown() throws Exception {
58 extractor = null;
59 }
6061 @Test
62publicvoid testExtractFromHTMLDocument()
63throws IOException, ExtractionException, TripleHandlerException {
64final IRI uri = RDFUtils.iri("http://podaac.jpl.nasa.gov/aquarius");
65 extract(uri, "/org/apache/any23/extractor/openie/example-openie.html");
66 }
6768publicvoid extract(IRI uri, String filePath)
69throws IOException, ExtractionException, TripleHandlerException {
70 FileOutputStream fos = new FileOutputStream(File.createTempFile("OpenIEExtractorTest", "tmp"));
71final TripleHandler tHandler = new RDFXMLWriter(fos);
72final ExtractionContext extractionContext = new ExtractionContext("rdf-openie", uri);
73final ExtractionResult result = new ExtractionResultImpl(extractionContext, extractor, tHandler);
74try {
75 extractor.run(
76 ExtractionParameters.newDefault(),
77 extractionContext,
78 StreamUtils.inputStreamToDocument(this.getClass().getResourceAsStream(filePath)),
79 result
80 );
81 } finally {
82 logger.debug(fos.toString());
83 tHandler.close();
84 result.close();
85 }
86 }
8788 }