MCPcopy Create free account
hub / github.com/GateNLP/gate-core / extractParserTips

Method extractParserTips

src/main/java/gate/corpora/TikaFormat.java:166–190  ·  view source on GitHub ↗

Tries to extract tips for the parser as specified here - http://tika.apache.org/0.7/parser.html . The tips are not critical for successful parsing. @param doc @return metadata, not null but may be empty

(Document doc)

Source from the content-addressed store, hash-verified

164 * @return metadata, not null but may be empty
165 */
166 private Metadata extractParserTips(Document doc) {
167 Metadata metadata = new Metadata();
168 Object inputMime = doc.getFeatures().get("MimeType");
169 if (inputMime instanceof String) {
170 if (!"application/tika".equals(inputMime)) {
171 metadata.add(Metadata.CONTENT_TYPE, (String) doc.getFeatures().get("MimeType"));
172 }
173 }
174 if (doc instanceof DocumentImpl) {
175 if (((DocumentImpl)doc).getMimeType() != null) {
176 metadata.add(Metadata.CONTENT_TYPE, ((DocumentImpl)doc).getMimeType());
177 }
178 }
179 if (doc.getSourceUrl() != null && doc.getSourceUrl().getProtocol().startsWith("file")) {
180 try {
181 File fn =new File(doc.getSourceUrl().toURI());
182 metadata.add(Metadata.RESOURCE_NAME_KEY, fn.getName());
183 } catch (URISyntaxException e) {
184 log.debug("Could not extract filename from uri: " + doc.getSourceUrl(), e);
185 } catch (IllegalArgumentException e) {
186 log.debug("Could not extract filename from uri: " + doc.getSourceUrl(), e);
187 }
188 }
189 return metadata;
190 }
191}

Callers 1

unpackMarkupMethod · 0.95

Calls 8

toURIMethod · 0.80
getMethod · 0.65
getFeaturesMethod · 0.65
equalsMethod · 0.65
addMethod · 0.65
getSourceUrlMethod · 0.65
getNameMethod · 0.65
getMimeTypeMethod · 0.45

Tested by

no test coverage detected