File size: 4,026 Bytes
6f3ebfa | 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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | package org.maltparser.parser;
import org.maltparser.core.exception.MaltChainedException;
import org.maltparser.core.symbol.SymbolTable;
import org.maltparser.core.symbol.SymbolTableHandler;
import org.maltparser.core.syntaxgraph.DependencyStructure;
import org.maltparser.core.syntaxgraph.edge.Edge;
import org.maltparser.core.syntaxgraph.node.DependencyNode;
import org.maltparser.parser.guide.ClassifierGuide;
/**
* @author Johan Hall
*
*/
public abstract class ParsingAlgorithm implements AlgoritmInterface {
protected final DependencyParserConfig manager;
protected final ParserRegistry registry;
protected ClassifierGuide classifierGuide;
protected final ParserState parserState;
protected ParserConfiguration currentParserConfiguration;
/**
* Creates a parsing algorithm
*
* @param _manager a reference to the single malt configuration
* @param symbolTableHandler a reference to the symbol table handler
* @throws MaltChainedException
*/
public ParsingAlgorithm(DependencyParserConfig _manager, SymbolTableHandler symbolTableHandler) throws MaltChainedException {
this.manager = _manager;
this.registry = new ParserRegistry();
registry.setSymbolTableHandler(symbolTableHandler);
registry.setDataFormatInstance(manager.getDataFormatInstance());
registry.setAbstractParserFeatureFactory(manager.getParserFactory());
parserState = new ParserState(manager, symbolTableHandler, manager.getParserFactory());
}
public abstract void terminate() throws MaltChainedException;
public ParserRegistry getParserRegistry() {
return registry;
}
/**
* Returns the classifier guide.
*
* @return the classifier guide
*/
public ClassifierGuide getGuide() {
return classifierGuide;
}
/**
* Sets the classifier guide
*
* @param guide a classifier guide
*/
public void setGuide(ClassifierGuide guide) {
this.classifierGuide = guide;
}
/**
* Returns the current active parser configuration
*
* @return the current active parser configuration
*/
public ParserConfiguration getCurrentParserConfiguration() {
return currentParserConfiguration;
}
/**
* Sets the current parser configuration
*
* @param currentParserConfiguration a parser configuration
*/
protected void setCurrentParserConfiguration(ParserConfiguration currentParserConfiguration) {
this.currentParserConfiguration = currentParserConfiguration;
}
/**
* Returns the parser state
*
* @return the parser state
*/
public ParserState getParserState() {
return parserState;
}
/**
* Returns the single malt configuration
*
* @return the single malt configuration
*/
public DependencyParserConfig getManager() {
return manager;
}
/**
* Copies the edges of the source dependency structure to the target dependency structure
*
* @param source a source dependency structure
* @param target a target dependency structure
* @throws MaltChainedException
*/
protected void copyEdges(DependencyStructure source, DependencyStructure target) throws MaltChainedException {
for (int index : source.getTokenIndices()) {
DependencyNode snode = source.getDependencyNode(index);
if (snode.hasHead()) {
Edge s = snode.getHeadEdge();
Edge t = target.addDependencyEdge(s.getSource().getIndex(), s.getTarget().getIndex());
for (SymbolTable table : s.getLabelTypes()) {
t.addLabel(table, s.getLabelSymbol(table));
}
}
}
}
protected void copyDynamicInput(DependencyStructure source, DependencyStructure target) throws MaltChainedException {
for (int index : source.getTokenIndices()) {
DependencyNode snode = source.getDependencyNode(index);
DependencyNode tnode = target.getDependencyNode(index);
for (SymbolTable table : snode.getLabelTypes()) {
if (!tnode.hasLabel(table)) {
tnode.addLabel(table,snode.getLabelSymbol(table));
}
}
}
}
}
|