2016-11-19 6 views
1

私はuima rutaの例を試しています: hereです。UIMA Ruta - 基本例

私はrutaスクリプトを作成してテキストに適用したいです(ワークベンチのないプレーンJavaから)。

1.私はプレーン・ジャバ(ワークベンチなし)からタイプ・システム・ディスクリプタを取得していますか? 2.いつワークベンチで入手できますか? (もし私がrutaスクリプトを "実行"しても、説明はありませんでした)

答えて

2

主な質問は、スクリプトが新しいタイプを宣言するかどうかです。

新しいタイプが宣言されていない場合は、ドキュメント内のリンクされた例で十分です。

新しいタイプがスクリプトで宣言されている場合は、タイプシステムの記述を作成してCASの作成プロセスに組み込んでから、スクリプトをCASに適用する必要があります。

スクリプト内で宣言されたタイプのタイプの記述を含むスクリプトのタイプのシステム記述は、以下の方法で作成することができる。

  • ルタWorkbenchが簡単内の各スクリプトの自動型システム記述を作成しますスクリプトが保存されるときにRutaプロジェクト。説明が作成されていない場合、スクリプトは解析できない可能性が高く、構文エラーが含まれています。
  • メイドビルドプロジェクトでは、ruta-maven-pluginを使用して、Rutaスクリプトのタイプシステム記述を作成できます。
  • プレーンJavaでは、RutaDescriptorFactoryを使用して、タイプのシステム記述をプログラムで作成することができます。ここにはcode exampleがあります。

ルータベースの解析エンジンをプレーンJavaコードで作成して実行するには、いくつかの方法があります。ここでの例では、追加のファイルを使用せずにです:

String rutaScript = "DECLARE MyType; CW{-> MyType};"; 

RutaDescriptorFactory descriptorFactory = new RutaDescriptorFactory(); 
RutaBuildOptions options = new RutaBuildOptions(); 
options.setResolveImports(true); 
options.setImportByName(true); 
RutaDescriptorInformation descriptorInformation = descriptorFactory 
     .parseDescriptorInformation(rutaScript, options); 
// replace null values for build environment if necessary (e.g., location in classpath) 
Pair<AnalysisEngineDescription, TypeSystemDescription> descriptions = descriptorFactory 
     .createDescriptions(null, null, descriptorInformation, options, null, null, null); 

AnalysisEngineDescription rutaAnalysisEngineDescription = descriptions.getKey(); 
rutaAnalysisEngineDescription.getAnalysisEngineMetaData().getConfigurationParameterSettings().setParameterValue(RutaEngine.PARAM_RULES, rutaScript); 
TypeSystemDescription rutaTypeSystemDescription = descriptions.getValue(); 
// directly set type system description since no file will be created 
rutaAnalysisEngineDescription.getAnalysisEngineMetaData().setTypeSystem(rutaTypeSystemDescription); 

ResourceManager resourceManager = UIMAFramework.newDefaultResourceManager(); 
AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(rutaAnalysisEngineDescription); 

List<TypeSystemDescription> typeSystemDescriptions = new ArrayList<>(); 
TypeSystemDescription scannedTypeSystemDescription = TypeSystemDescriptionFactory.createTypeSystemDescription(); 
typeSystemDescriptions.add(scannedTypeSystemDescription); 
typeSystemDescriptions.add(rutaTypeSystemDescription); 
TypeSystemDescription mergeTypeSystemDescription = CasCreationUtils.mergeTypeSystems(typeSystemDescriptions, resourceManager); 

JCas jCas = JCasFactory.createJCas(mergeTypeSystemDescription); 
CAS cas = jCas.getCas(); 
jCas.setDocumentText("This is my document."); 
ae.process(jCas); 

Collection<AnnotationFS> select = CasUtil.select(cas, cas.getTypeSystem().getType("Anonymous.MyType")); 
for (AnnotationFS each : select) { 
    System.out.println(each.getCoveredText()); 
} 

免責事項:私は、UIMAルタ

+0

のデベロッパーあなたの答えをいただき、ありがとうございます。私はRutaDescriptorFactoryの例を理解しているかどうかはわかりません...上記の例([link](https://uima.apache.org/d/ruta-current/tools.ruta.book.html) #ugr.tools.ruta.ae.basic.apply)) – CyKon

+0

回答を延長します –

+0

ありがとうございます! :-) – CyKon

関連する問題