Situation: Sie haben einen korrekten XML-Descriptor einer UIMA Ruta Analyse-Engine und Sie wollen so neu konfigurieren, dass die Pfade in den Ordnern der descriptor.java url
Punkt
Der folgende Code zeigt, dass durch eine Änderung in Datei die Parameterwerte in verschiedenen Stufen. Nur eine Stufe ist erforderlich. Was für Sie die richtige ist, hängt von Ihrem Code ab.
package example;
import java.io.File;
import java.net.URL;
import org.apache.uima.analysis_engine.AnalysisEngine;
import org.apache.uima.analysis_engine.AnalysisEngineDescription;
import org.apache.uima.fit.factory.AnalysisEngineFactory;
import org.apache.uima.resource.metadata.ConfigurationParameterSettings;
import org.apache.uima.ruta.engine.RutaEngine;
public class ReconfigureExample {
public static void main(String[] args) throws Exception {
File file = new File("path to descriptor");
String path = new File(file.toURI()).getParentFile().getAbsolutePath();
String[] pathsArray = new String[] { path };
// override the values in the descriptor when creating the description
AnalysisEngineDescription desc = AnalysisEngineFactory.createEngineDescriptionFromPath(
file.getAbsolutePath(), RutaEngine.PARAM_SCRIPT_PATHS, pathsArray,
RutaEngine.PARAM_DESCRIPTOR_PATHS, pathsArray, RutaEngine.PARAM_RESOURCE_PATHS,
pathsArray);
// in case the location of the descriptor is not known...
URL sourceUrl = desc.getSourceUrl();
path = new File(sourceUrl.toURI()).getParentFile().getAbsolutePath();
pathsArray = new String[] { path };
// set the values in the description
ConfigurationParameterSettings settings = desc.getAnalysisEngineMetaData()
.getConfigurationParameterSettings();
settings.setParameterValue(RutaEngine.PARAM_SCRIPT_PATHS, pathsArray);
settings.setParameterValue(RutaEngine.PARAM_DESCRIPTOR_PATHS, pathsArray);
settings.setParameterValue(RutaEngine.PARAM_RESOURCE_PATHS, pathsArray);
// override the values in the descriptor when creating the analysis engine
AnalysisEngine ae = AnalysisEngineFactory.createEngine(desc, RutaEngine.PARAM_SCRIPT_PATHS, pathsArray,
RutaEngine.PARAM_DESCRIPTOR_PATHS, pathsArray, RutaEngine.PARAM_RESOURCE_PATHS,
pathsArray);
// set the values in the analysis engine and reconfigure it
ae.setConfigParameterValue(RutaEngine.PARAM_SCRIPT_PATHS, pathsArray);
ae.setConfigParameterValue(RutaEngine.PARAM_DESCRIPTOR_PATHS, pathsArray);
ae.setConfigParameterValue(RutaEngine.PARAM_RESOURCE_PATHS, pathsArray);
ae.reconfigure();
}
}
HAFTUNGSAUSSCHLUSS: Ich bin ein Entwickler von UIMA Ruta