本文整理汇总了Java中org.maltparser.MaltParserService类的典型用法代码示例。如果您正苦于以下问题:Java MaltParserService类的具体用法?Java MaltParserService怎么用?Java MaltParserService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MaltParserService类属于org.maltparser包,在下文中一共展示了MaltParserService类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import org.maltparser.MaltParserService; //导入依赖的package包/类
@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
super.initialize(context);
try {
OptionManager.instance().loadOptionDescriptionFile();
OptionManager.instance().getOptionDescriptions().generateMaps();
this.service = new MaltParserService();
File modelFile = new File(this.modelFileName);
String fileName = modelFile.getName();
String workingDirectory = modelFile.getParent();
String command = String.format("-c %s -m parse -w %s", fileName, workingDirectory);
this.service.initializeParserModel(command);
} catch (MaltChainedException e) {
throw new ResourceInitializationException(e);
}
}
示例2: ParserMalt
import org.maltparser.MaltParserService; //导入依赖的package包/类
public ParserMalt(){
try {
Properties props = new Properties();
props.put("customAnnotatorClass.cleanprefix", "ca.ualberta.exemplar.core.CleanPrefixAnnotator");
props.put("customAnnotatorClass.locationjuxtaposition", "ca.ualberta.exemplar.core.LocationJuxtapositionAnnotator");
props.put("customAnnotatorClass.removedashes", "ca.ualberta.exemplar.core.RemoveDashesAnnotator");
props.put("annotators", "tokenize, ssplit, removedashes, pos, lemma, ner, cleanprefix, locationjuxtaposition");
pipeline = new StanfordCoreNLP(props);
maltParser = new MaltParserService();
maltParser.initializeParserModel("-c " + Paths.MALT_PARSER_FILENAME
+ " -w " + Paths.MALT_PARSER_DIRECTORY + " -m parse");
// Used to map from malt relations to Stanford relations
relationMap = new HashMap<String,String>();
relationMap.put("measure", "npadvmod");
} catch (Exception e) {
e.printStackTrace();
}
}
示例3: main
import org.maltparser.MaltParserService; //导入依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
try {
String trainingDataFile = ".."+File.separator+"data"+File.separator+"talbanken05_train.conll";
// Trains the parser model model0.mco and uses the option container 0
new MaltParserService(0).runExperiment("-c model0 -i "+trainingDataFile+" -m learn -ne true -nr false");
// Trains the parser model model1.mco and uses the option container 1
new MaltParserService(1).runExperiment("-c model1 -i "+trainingDataFile+" -m learn -ne true -nr true");
} catch (MaltChainedException e) {
System.err.println("MaltParser exception : " + e.getMessage());
}
}
示例4: main
import org.maltparser.MaltParserService; //导入依赖的package包/类
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("Usage: ");
System.out.println(" java -cp classes:../../malt.jar org.maltparser.examples.OptionFreeInitialization <data format file>");
System.out.println("Example: ");
System.out.println(" java -cp classes:../../malt.jar org.maltparser.examples.OptionFreeInitialization ../../appdata/dataformat/conllx.xml");
return;
}
try {
// Create a MaltParserService object without option manager
MaltParserService service = new MaltParserService(true);
// Creates an array of tokens, which contains the Swedish sentence 'Grundavdraget upphör alltså vid en taxerad inkomst på 52500 kr.'
// in the CoNLL data format.
String[] tokens = new String[11];
tokens[0] = "1\tGrundavdraget\t_\tN\tNN\tDD|SS\t2\tSS";
tokens[1] = "2\tupphör\t_\tV\tVV\tPS|SM\t0\tROOT";
tokens[2] = "3\talltså\t_\tAB\tAB\tKS\t2\t+A";
tokens[3] = "4\tvid\t_\tPR\tPR\t_\t2\tAA";
tokens[4] = "5\ten\t_\tN\tEN\t_\t7\tDT";
tokens[5] = "6\ttaxerad\t_\tP\tTP\tPA\t7\tAT";
tokens[6] = "7\tinkomst\t_\tN\tNN\t_\t4\tPA";
tokens[7] = "8\tpå\t_\tPR\tPR\t_\t7\tET";
tokens[8] = "9\t52500\t_\tR\tRO\t_\t10\tDT";
tokens[9] = "10\tkr\t_\tN\tNN\t_\t8\tPA";
tokens[10] = "11\t.\t_\tP\tIP\t_\t2\tIP";
// Print out the string array
for (int i = 0; i < tokens.length; i++) {
System.out.println(tokens[i]);
}
// Reads the data format specification file
DataFormatSpecification dataFormatSpecification = service.readDataFormatSpecification(args[0]);
// Use the data format specification file to build a dependency structure based on the string array
DependencyStructure graph = service.toDependencyStructure(tokens, dataFormatSpecification);
// Print the dependency structure
System.out.println(graph);
} catch (MaltChainedException e) {
System.err.println("MaltParser exception: " + e.getMessage());
}
}
示例5: main
import org.maltparser.MaltParserService; //导入依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
try {
MaltParserService service = new MaltParserService();
// Inititalize the parser model 'model0' and sets the working directory to '.' and sets the logging file to 'parser.log'
service.initializeParserModel("-c model0 -m parse -w . -lfi parser.log");
// Creates an array of tokens, which contains the Swedish sentence 'Grundavdraget upphör alltså vid en taxerad inkomst på 52500 kr.'
// in the CoNLL data format.
String[] tokens = new String[11];
tokens[0] = "1\tGrundavdraget\t_\tN\tNN\tDD|SS";
tokens[1] = "2\tupphör\t_\tV\tVV\tPS|SM";
tokens[2] = "3\talltså\t_\tAB\tAB\tKS";
tokens[3] = "4\tvid\t_\tPR\tPR\t_";
tokens[4] = "5\ten\t_\tN\tEN\t_";
tokens[5] = "6\ttaxerad\t_\tP\tTP\tPA";
tokens[6] = "7\tinkomst\t_\tN\tNN\t_";
tokens[7] = "8\tpå\t_\tPR\tPR\t_";
tokens[8] = "9\t52500\t_\tR\tRO\t_";
tokens[9] = "10\tkr\t_\tN\tNN\t_";
tokens[10] = "11\t.\t_\tP\tIP\t_";
// Parses the Swedish sentence above
String[] outputTokens = service.parseTokens(tokens);
// Outputs the with the head index and dependency type information
for (int i = 0; i < outputTokens.length; i++) {
System.out.println(outputTokens[i]);
}
// Terminates the parser model
service.terminateParserModel();
} catch (MaltChainedException e) {
System.err.println("MaltParser exception: " + e.getMessage());
}
}
示例6: main
import org.maltparser.MaltParserService; //导入依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
try {
MaltParserService service = new MaltParserService();
// Inititalize the parser model 'model0' and sets the working directory to '.' and sets the logging file to 'parser.log'
service.initializeParserModel("-c model0 -m parse -w . -lfi parser.log");
// Creates an array of tokens, which contains the Swedish sentence 'Grundavdraget upphör alltså vid en taxerad inkomst på 52500 kr.'
// in the CoNLL data format.
String[] tokens = new String[11];
tokens[0] = "1\tGrundavdraget\t_\tN\tNN\tDD|SS";
tokens[1] = "2\tupphör\t_\tV\tVV\tPS|SM";
tokens[2] = "3\talltså\t_\tAB\tAB\tKS";
tokens[3] = "4\tvid\t_\tPR\tPR\t_";
tokens[4] = "5\ten\t_\tN\tEN\t_";
tokens[5] = "6\ttaxerad\t_\tP\tTP\tPA";
tokens[6] = "7\tinkomst\t_\tN\tNN\t_";
tokens[7] = "8\tpå\t_\tPR\tPR\t_";
tokens[8] = "9\t52500\t_\tR\tRO\t_";
tokens[9] = "10\tkr\t_\tN\tNN\t_";
tokens[10] = "11\t.\t_\tP\tIP\t_";
// Parses the Swedish sentence above
DependencyStructure graph = service.parse(tokens);
// Outputs the dependency graph created by MaltParser.
System.out.println(graph);
// Terminates the parser model
service.terminateParserModel();
} catch (MaltChainedException e) {
System.err.println("MaltParser exception: " + e.getMessage());
}
}
示例7: main
import org.maltparser.MaltParserService; //导入依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
try {
MaltParserService service = new MaltParserService();
// Inititalize the parser model 'model0' and sets the working directory to '.' and sets the logging file to 'parser.log'
service.initializeParserModel("-u jar:file:mco_nested_in_jar.jar!/model0.mco -m parse -w . -lfi parser.log -v debug");
// Creates an array of tokens, which contains the Swedish sentence 'Grundavdraget upphör alltså vid en taxerad inkomst på 52500 kr.'
// in the CoNLL data format.
String[] tokens = new String[11];
tokens[0] = "1\tGrundavdraget\t_\tN\tNN\tDD|SS";
tokens[1] = "2\tupphör\t_\tV\tVV\tPS|SM";
tokens[2] = "3\talltså\t_\tAB\tAB\tKS";
tokens[3] = "4\tvid\t_\tPR\tPR\t_";
tokens[4] = "5\ten\t_\tN\tEN\t_";
tokens[5] = "6\ttaxerad\t_\tP\tTP\tPA";
tokens[6] = "7\tinkomst\t_\tN\tNN\t_";
tokens[7] = "8\tpå\t_\tPR\tPR\t_";
tokens[8] = "9\t52500\t_\tR\tRO\t_";
tokens[9] = "10\tkr\t_\tN\tNN\t_";
tokens[10] = "11\t.\t_\tP\tIP\t_";
// Parses the Swedish sentence above
String[] outputTokens = service.parseTokens(tokens);
// Outputs the with the head index and dependency type information
for (int i = 0; i < outputTokens.length; i++) {
System.out.println(outputTokens[i]);
}
// Terminates the parser model
service.terminateParserModel();
} catch (MaltChainedException e) {
System.err.println("MaltParser exception: " + e.getMessage());
e.printStackTrace();
}
}
示例8: main
import org.maltparser.MaltParserService; //导入依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
try {
String testDataFile = ".."+File.separator+"data"+File.separator+"talbanken05_test.conll";
// Parses the test data file using the parser model model0.mco and using the option container 0
new MaltParserService(0).runExperiment("-c model0 -i "+testDataFile+" -o out1.conll -m parse");
// Parses the test data file using the parser model model1.mco and using the option container 1
new MaltParserService(1).runExperiment("-c model1 -i "+testDataFile+" -o out2.conll -m parse");
} catch (MaltChainedException e) {
System.err.println("MaltParser exception : " + e.getMessage());
}
}