Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何获取字典注释器的注释文本_Java_Artificial Intelligence_Opennlp_Uimanageddocument_Uima - Fatal编程技术网

Java 如何获取字典注释器的注释文本

Java 如何获取字典注释器的注释文本,java,artificial-intelligence,opennlp,uimanageddocument,uima,Java,Artificial Intelligence,Opennlp,Uimanageddocument,Uima,我有一个从UIMA的DictionaryCreator创建的字典,我想用DictionaryNotator和前面提到的字典注释一段文本,我不知道如何获得注释文本。如果有,请告诉我。感谢您的帮助。代码、字典文件和描述符如下所述, 另外,我对ApacheUIMA还不熟悉 XMLInputSource xml_in = new XMLInputSource("DictionaryAnnotatorDescriptor.xml"); ResourceSpecifier specifi

我有一个从UIMA的DictionaryCreator创建的字典,我想用DictionaryNotator和前面提到的字典注释一段文本,我不知道如何获得注释文本。如果有,请告诉我。感谢您的帮助。代码、字典文件和描述符如下所述, 另外,我对ApacheUIMA还不熟悉

 XMLInputSource xml_in = new XMLInputSource("DictionaryAnnotatorDescriptor.xml");
         ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(xml_in);
         AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
         JCas jCas = ae.newJCas();
         String inputText = "Mark and John went down the rabbit hole to meet a wise owl and have curry with the owl.";
         jCas.setDocumentText(inputText);
         printResults(jCas);


public static void printResults(JCas jcas) {
    FSIndex<Annotation> index = jcas.getAnnotationIndex();
    for (Iterator<Annotation> it = index.iterator(); it.hasNext(); ) {
        Annotation annotation = it.next();
        List<Feature> features;
            features = annotation.getType().getFeatures();
        List<String> fasl = new ArrayList<String>();
        for (Feature feature : features) {
            try {
                String name = feature.getShortName();
                System.out.println(feature.getName());
                String value = annotation.getStringValue(feature);
                fasl.add(name + "=\"" + value + "\"");
                System.out.println(value);
            }catch (Exception e){
                continue;
            }
        }
    }
}


my_dictionary.xml
<?xml version="1.0" encoding="UTF-8"?>
<dictionary xmlns="http://incubator.apache.org/uima" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="dictionary.xsd">
<typeCollection>
<dictionaryMetaData caseNormalization="true" multiWordEntries="true" multiWordSeparator=" "/>
<languageId>en</languageId>
<typeDescription>
<typeName>org.apache.uima.DictionaryEntry</typeName>
</typeDescription>
<entries>
<entry>
<key>Mark</key>
</entry>
<entry>
<key>John</key>
</entry>
<entry>
<key>Rabbit</key>
</entry>
<entry>
<key>Owl</key>
</entry>
<entry>
<key>Curry</key>
</entry>
<entry>
<key>ATH-MX50</key>
</entry>
<entry>
<key>CC234</key>
</entry>
</entries>
</typeCollection>
</dictionary>

DictionaryAnnotatorDescriptor.xml

<?xml version="1.0" encoding="UTF-8"?>
<analysisEngineDescription xmlns="http://uima.apache.org/resourceSpecifier">
    <frameworkImplementation>org.apache.uima.java</frameworkImplementation>
    <primitive>true</primitive>
    <annotatorImplementationName>org.apache.uima.annotator.dict_annot.impl.DictionaryAnnotator</annotatorImplementationName>
    <analysisEngineMetaData>
        <name>GeneDictionaryAnnotator</name>
        <description></description>
        <version>0.1</version>
        <vendor></vendor>
        <configurationParameters>
            <configurationParameter>
                <name>DictionaryFiles</name>
                <description>list of dictionary files to configure the annotator</description>
                <type>String</type>
                <multiValued>true</multiValued>
                <mandatory>true</mandatory>
            </configurationParameter>
            <configurationParameter>
                <name>InputMatchType</name>
                <description></description>
                <type>String</type>
                <multiValued>false</multiValued>
                <mandatory>true</mandatory>
            </configurationParameter>
            <configurationParameter>
                <name>InputMatchFeaturePath</name>
                <description></description>
                <type>String</type>
                <multiValued>false</multiValued>
                <mandatory>false</mandatory>
            </configurationParameter>
            <configurationParameter>
                <name>InputMatchFilterFeaturePath</name>
                <description></description>
                <type>String</type>
                <multiValued>false</multiValued>
                <mandatory>false</mandatory>
            </configurationParameter>
            <configurationParameter>
                <name>FilterConditionOperator</name>
                <description></description>
                <type>String</type>
                <multiValued>false</multiValued>
                <mandatory>false</mandatory>
            </configurationParameter>
            <configurationParameter>
                <name>FilterConditionValue</name>
                <description></description>
                <type>String</type>
                <multiValued>false</multiValued>
                <mandatory>false</mandatory>
            </configurationParameter>
        </configurationParameters>
        <configurationParameterSettings>
            <nameValuePair>
                <name>DictionaryFiles</name>
                <value>
                    <array>
                        <string>src/main/resources/my_dictionary.xml</string>
                    </array>
                </value>
            </nameValuePair>
            <nameValuePair>
                <name>InputMatchType</name>
                <value>
                    <string>org.apache.uima.TokenAnnotation</string>
                </value>
            </nameValuePair>
        </configurationParameterSettings>
        <typeSystemDescription>
            <types>
                <typeDescription>
                    <name>org.apache.uima.DictionaryEntry</name>
                    <description></description>
                    <supertypeName>uima.tcas.Annotation</supertypeName>
                </typeDescription>
                <typeDescription>
                    <name>org.apache.uima.TokenAnnotation</name>
                    <description>Single token annotation</description>
                    <supertypeName>uima.tcas.Annotation</supertypeName>
                    <features>
                        <featureDescription>
                            <name>tokenType</name>
                            <description>token type</description>
                            <rangeTypeName>uima.cas.String</rangeTypeName>
                        </featureDescription>
                    </features>
                </typeDescription>
                <typeDescription>
                    <name>example.Name</name>
                    <description>A proper name.</description>
                    <supertypeName>uima.tcas.Annotation</supertypeName>
                </typeDescription>
            </types>
        </typeSystemDescription>
        <capabilities>
            <capability>
                <inputs/>
                <outputs>
                    <type>example.Name</type>
                </outputs>
                <languagesSupported/>
            </capability>
        </capabilities>
        <operationalProperties>
            <modifiesCas>true</modifiesCas>
            <multipleDeploymentAllowed>true</multipleDeploymentAllowed>
            <outputsNewCASes>false</outputsNewCASes>
        </operationalProperties>
    </analysisEngineMetaData>
</analysisEngineDescription>
XMLInputSource xml_in=newxmlinputsource(“DictionaryAnnotatorDescriptor.xml”);
ResourceSpecifier说明符=UIMAFramework.getXMLParser().parseResourceSpecifier(xml_-in);
AnalysisEngine ae=UIMAFramework.produceAnalysisEngine(说明符);
JCas JCas=ae.newJCas();
String inputText=“马克和约翰去兔子洞见了一只聪明的猫头鹰,并和猫头鹰一起吃咖喱。”;
jCas.setDocumentText(输入文本);
打印结果(jCas);
公共静态void打印结果(JCas JCas){
FSIndex=jcas.getAnnotationIndex();
for(Iterator it=index.Iterator();it.hasNext();){
Annotation=it.next();
列出特征;
features=annotation.getType().getFeatures();
List fasl=new ArrayList();
用于(特征:特征){
试一试{
字符串名称=feature.getShortName();
System.out.println(feature.getName());
字符串值=注释.getStringValue(特征);
fasl.add(name+“=\”+value+“\”);
系统输出打印项次(值);
}捕获(例外e){
继续;
}
}
}
}
my_dictionary.xml
EN
org.apache.uima.DictionaryEntry
做记号
约翰
兔子
猫头鹰
咖喱
ATH-MX50
CC234
DictionaryAnnotatorDescriptor.xml
org.apache.uima.java
真的
org.apache.uima.annotator.dict_annot.impl.DictionaryAnnotator
基因词典注释员
0.1
字典文件
用于配置注释器的词典文件列表
一串
真的
真的
输入匹配类型
一串
假的
真的
InputMatchFeaturePath
一串
假的
假的
InputMatchFilterFeaturePath
一串
假的
假的
过滤条件算子
一串
假的
假的
过滤条件值
一串
假的
假的
字典文件
src/main/resources/my_dictionary.xml
输入匹配类型
org.apache.uima.TokenAnnotation
org.apache.uima.DictionaryEntry
uima.tcas.Annotation
org.apache.uima.TokenAnnotation
单标记注释
uima.tcas.Annotation
令牌类型
令牌类型
uima.cas.String
例如:姓名
正名。
uima.tcas.Annotation
例如:姓名
真的
真的
假的

或者,您也可以在工作台(建议开始使用)或java代码中使用

对于后者,我在创建了一个示例项目。主要部分包括:

src/main/resources/ruta/resources/names.txt中的名称列表(纯文本文件)

src/main/resources/Ruta/scripts/Example.Ruta中的Ruta脚本

PACKAGE example.annotate;               // optional package def

WORDLIST MyNames = 'names.txt';         // declare dictionary location
DECLARE Name;                           // declare an annotation
Document{-> MARKFAST(Name, MyNames)};   // annotate document
和一些java样板代码来启动注释器:

JCas jCas = JCasFactory.createJCas();

// the sample text to annotate
jCas.setDocumentText("Mark wants to buy CC234.");

// configure the engine with scripts and resources
AnalysisEngine rutaEngine = AnalysisEngineFactory.createEngine(
    RutaEngine.class, //
    RutaEngine.PARAM_RESOURCE_PATHS,
    "src/main/resources/ruta/resources",//
    RutaEngine.PARAM_SCRIPT_PATHS,
    "src/main/resources/ruta/scripts",
    RutaEngine.PARAM_MAIN_SCRIPT, "Example");

// run the script. instead of a jCas, you could also provide a UIMA collection reader to process many documents
SimplePipeline.runPipeline(jCas, rutaEngine);

// a simple select to print the matched Names
for (Name name : JCasUtil.select(jCas, Name.class)) {
    System.out.println(name.getCoveredText());
}
还有一些UIMA类型(注释)定义,检查
src/main/resources/desc/type/ExampleTypes.xml
src/main/resources/META-INF/org.apache.UIMA.fit/types.txt
src/main/java/example/annotate

如何测试它
或者,您也可以使用,或者与工作台(推荐入门)一起使用,或者与java代码一起使用

对于后者,我在创建了一个示例项目。主要部分包括:

src/main/resources/ruta/resources/names.txt中的名称列表(纯文本文件)

src/main/resources/Ruta/scripts/Example.Ruta中的Ruta脚本

PACKAGE example.annotate;               // optional package def

WORDLIST MyNames = 'names.txt';         // declare dictionary location
DECLARE Name;                           // declare an annotation
Document{-> MARKFAST(Name, MyNames)};   // annotate document
和一些java样板代码来启动注释器:

JCas jCas = JCasFactory.createJCas();

// the sample text to annotate
jCas.setDocumentText("Mark wants to buy CC234.");

// configure the engine with scripts and resources
AnalysisEngine rutaEngine = AnalysisEngineFactory.createEngine(
    RutaEngine.class, //
    RutaEngine.PARAM_RESOURCE_PATHS,
    "src/main/resources/ruta/resources",//
    RutaEngine.PARAM_SCRIPT_PATHS,
    "src/main/resources/ruta/scripts",
    RutaEngine.PARAM_MAIN_SCRIPT, "Example");

// run the script. instead of a jCas, you could also provide a UIMA collection reader to process many documents
SimplePipeline.runPipeline(jCas, rutaEngine);

// a simple select to print the matched Names
for (Name name : JCasUtil.select(jCas, Name.class)) {
    System.out.println(name.getCoveredText());
}
还有一些UIMA类型(注释)定义,检查
src/main/resources/desc/type/ExampleTypes.xml
src/main/resources/META-INF/org.apache.UIMA.fit/types.txt
src/main/java/example/annotate

如何测试它
谢谢你,雷诺!我很感激!您还可以告诉我如何使其不区分大小写,例如,即使文本有如ath-mx50,也要进行注释吗?您可以将其设置为,如果单词长度超过x个字符,它将忽略大小写,请参阅JCas创建也应使用JCasFactory.createJCas()缩短。谢谢大家!我真的很感激。你也可以打电话给我吗