-
Notifications
You must be signed in to change notification settings - Fork 492
Expand file tree
/
Copy pathEntityLinker.java
More file actions
103 lines (95 loc) · 5 KB
/
EntityLinker.java
File metadata and controls
103 lines (95 loc) · 5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package opennlp.tools.entitylinker;
import java.io.IOException;
import java.util.List;
import opennlp.tools.util.Span;
/**
* EntityLinkers establish connections with external data to enrich extracted
* entities.
* <p>
* For instance, for Location entities a linker can be developed to
* look up each found location in a geonames gazetteer. Another example may be to
* find peoples' names and look them up in a database or active directory.
* Intended to return n best matches for any given search, but can also be
* implemented as deterministic.
*
* @param <T> A type that extends {@link Span}. {@link LinkedSpan} and {@link BaseLink}
* are available to provide this signature. Use:
* {@link EntityLinker}<LinkedSpan<BaseLink>> as a default.
*/
public interface EntityLinker<T extends Span> {
/**
* Initializes an {@link EntityLinker} and allows for passing properties
* through an {@code EntityLinkerFactory} into all impls dynamically.
* <p>
* {@link EntityLinker} impls should initialize reusable objects
* used by the impl in this method. If this is done, any errors will be
* captured and thrown by an {@code EntityLinkerFactory}.
*
* @param initializationData The {@link EntityLinkerProperties} that contains
* properties needed by the impl, as well as any
* other objects required.
* @throws IOException Thrown if IO errors occurred.
*/
void init(EntityLinkerProperties initializationData) throws IOException;
/**
* Links an entire document of named entities to an external source.
*
* @param doctext The full text of the document.
* @param sentences An array of {@link Span sentence spans}.
* @param tokensBySentence An array of {@link Span tokens spans} that correspond to
* each sentence. The outer array refers to the sentence, the inner
* array is the tokens for the outer sentence. Similar
* in nature to Map of SentenceIndex keys to List of
* tokens as values.
* @param namesBySentence An array of {@link Span name spans} that correspond to each
* sentence. The outer array refers to the sentence,
* the inner array refers to the tokens that for the
* same sentence. Similar in nature to
* Map<SentenceIndex,List<Name Spans For This
* Sentence's Tokens>> @ return.
*
* @return A list of {@link T} instances.
*/
List<T> find(String doctext, Span[] sentences, Span[][] tokensBySentence, Span[][] namesBySentence);
/**
* Links the names that correspond to the tokens[] spans. The {@code sentenceIndex}
* can be used to get the sentence text and tokens from the text based on the
* sentence and token spans. The text is available for additional context.
*
* @param doctext The full text of the document.
* @param sentences An array of {@link Span sentence spans}.
* @param tokensBySentence An array of {@link Span tokens spans} that correspond to each
* sentence. The outer array refers to the sentence, the inner
* array is the tokens for the outer sentence. Similar
* in nature to Map of SentenceIndex keys to List of
* tokens as values.
* @param namesBySentence An array of {@link Span name spans} that correspond to each
* sentence. The outer array refers to the sentence,
* the inner array refers to the tokens that for the
* same sentence. Similar in nature to
* Map<SentenceIndex,List<Name Spans For This
* Sentence's Tokens>> @ return.
* @param sentenceIndex The index to the sentence span that the {@code tokensBySentence}
* corresponds to.
*
* @return A list of {@link T} instances.
*/
List<T> find(String doctext, Span[] sentences, Span[][] tokensBySentence,
Span[][] namesBySentence, int sentenceIndex);
}