Skip to content

Commit

Permalink
Attempt to merge Celex morph additions with morph generation code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Janin committed Nov 21, 2014
2 parents 14a463f + a2fa036 commit 4446351
Show file tree
Hide file tree
Showing 22 changed files with 1,336 additions and 6 deletions.
2 changes: 2 additions & 0 deletions analyzer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export JYTHONPATH=compling.core/build/compling.core.jar:src/main
jython -m analyzer first.prefs
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified compling.core/build/compling.core.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.List;
import java.util.StringTokenizer;

import org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException;
// import org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException;

import java_cup.runtime.Symbol;

Expand Down
1 change: 1 addition & 0 deletions compling.core/source/compling/grammar/ecg/Grammar.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ public Construction(String name, String kind, Set<String> parents, Block formBlo
this.constructionalBlock = constructionalBlock;
this.kind = kind;
}


public void setMeaningBlock(Block meaningBlock) {
this.meaningBlock = meaningBlock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class LCPGrammarWrapper implements GrammarWrapper {
Grammar grammar;
private HashMap<String, List<String>> subtypeList = new HashMap<String, List<String>>();
private HashMap<String, List<Construction>> lexemeToLexicalConstructions = new HashMap<String, List<Construction>>();
// for lemmas and constructions
private HashMap<String, List<Construction>> lemmaToLexicalConstructions = new HashMap<String, List<Construction>>();

Construction morph;
Construction word;

Expand Down Expand Up @@ -123,6 +126,7 @@ public List<Construction> getLexicalConstruction(String lexeme) {
}
return lex;
}


public Set<Construction> getAllConcretePhrasalConstructions() {
Set<Construction> cxns = new LinkedHashSet<Construction>();
Expand Down
128 changes: 128 additions & 0 deletions compling.core/source/compling/parser/ecgparser/LeftCornerParser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package compling.parser.ecgparser;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
Expand All @@ -14,6 +15,8 @@
import compling.grammar.ecg.Grammar.Construction;
import compling.grammar.unificationgrammar.TypeSystem;
import compling.grammar.unificationgrammar.TypeSystemException;
import compling.grammar.unificationgrammar.UnificationGrammar;
import compling.grammar.unificationgrammar.UnificationGrammar.Constraint;
import compling.grammar.unificationgrammar.UnificationGrammar.Role;
import compling.parser.ParserException;
import compling.parser.RobustParser;
Expand Down Expand Up @@ -167,6 +170,9 @@ public int getNumberOfStatesProcessedForLastUtterance() {
}

public PriorityQueue<List<T>> getBestPartialParses(Utterance<Word, String> utterance) {



lastNormalizer = 0;
currentEntropy = 0;
parserLog = new StringBuilder();
Expand Down Expand Up @@ -199,9 +205,131 @@ public PriorityQueue<List<T>> getBestPartialParses(Utterance<Word, String> utter
.addQuotes(ECGConstants.UNKNOWN_ITEM));
input[i][0] = lexicalCxns.get(0);

// Try to process input string as lemma, after decomposing into morphological parts.
try {

// Get lemma output from Morph analyzer. For now, just set to "block".
String lemma = "block";

String[] morphs = new String[]{"Plural", "Present|!Participle"};



// beginnings of initializing a morph table hashmap. Should actually be initialized outside function. Though ideally inside grammar.
HashMap<String, String[]> meaning_morphTable = new HashMap<String, String[]>()
{{
put("Plural", new String[]{"self.m.number", "@plural"});
put("Singular", new String[]{"self.m.number", "@singular"});
// put("Singular", new String[]{"self.m.bounding", "@determinate"});
put("Past|!Participle", new String[]{"self.pf.tense", "@past"});
put("Present|!Participle", new String[]{"self.pf.tense", "@present"});
put("Comparative", new String[]{"self.m.kind", "@comparative"});
put("Superlative", new String[]{"self.m.kind", "@superlative"});
}};

// beginnings of initializing a morph table HashMap for constructional features.
HashMap<String, String[]> constructional_morphTable = new HashMap<String, String[]>()
{{
put("Plural", new String[]{"self.features.number", "\"plural\""});
put("Singular", new String[]{"self.features.number", "\"singular\""});
put("Present|!Participle", new String[]{"self.verbform", "Present"});
}};


// Search for lemma in constructions
List<Construction> lemmaCxns = grammar.getLemmaConstruction(StringUtilities.addQuotes(lemma)); //(StringUtilities.addQuotes(utterance.getElement(i).getOrthography()));

// make new list: input[i] = ??, based on size of lemmaCxns (but also based on combinations between morphed and lemmaCxns)
input[i] = new Construction[lemmaCxns.size()];

for (int j = 0; j < lemmaCxns.size(); j++) {
Construction cxn = lemmaCxns.get(j); // should actually make a copy of construction


//Construction cxn2 = new Construction("BlockTest2", cxn.getParents(), cxn.getFormBlock(), cxn.getMeaningBlock(), cxn.getConstructionalBlock());

// Procedure: iterate through constructional constraints.
// Check if constraint matches FlectTypes in constructional Table.
// Change value if true.

for (Constraint constraint: cxn.getConstructionalBlock().getConstraints()) {
if (constraint.getValue().replace("\"", "").equals("undetermined")) {
for (String morph : morphs) {
if (constraint.getArguments().toString().replace("]", "").replace("[", "").equals(constructional_morphTable.get(morph)[0])) {
constraint.setValue(constructional_morphTable.get(morph)[1]);
}
}
}

}

// Procedure: iterate through semantic constraints. For each constraint, check if any of returned FlectTypes match in preset HashMap.
// If they do match, change value of constraint to value specified in HashMap.


for (Constraint constraint : cxn.getMeaningBlock().getConstraints()) {
if (constraint.isAssign() && constraint.getValue().replace("\"", "").equals("undetermined")) {
for (String morph : morphs) {
//String arg = meaning_morphTable.get(morph)[0];
if (constraint.getArguments().toString().replace("]", "").replace("[", "")
.equals(meaning_morphTable.get(morph)[0])) {
constraint.setValue(meaning_morphTable.get(morph)[1]);
}
}

}
}

cloneTable.put(cxn);
cloneTable.update();

input[i][j] = cxn;

}

} catch (GrammarException g) {
System.out.println("Unknown input lemma: " + utterance.getElement(i).getOrthography());
input[i] = new Construction[1];
List<Construction> lexicalCxns = grammar.getLexicalConstruction(StringUtilities
.addQuotes(ECGConstants.UNKNOWN_ITEM));
input[i][0] = lexicalCxns.get(0);



}
// Currently this creates a new copy of the existing list, then adds to lexical Cxns list.
try {
List<Construction> lexicalCxns = grammar.getLexicalConstruction(StringUtilities.addQuotes(utterance.getElement(
i).getOrthography()));


Construction[] copy = new Construction[input[i].length + lexicalCxns.size()];
for (int k = 0; k < input[i].length; k++){
copy[k] = input[i][k];
}


Construction[] test = new Construction[lexicalCxns.size()]; //input[i] = new Construction[lexicalCxns.size()];
for (int j = 0; j < lexicalCxns.size(); j++) {
//System.out.println("i:"+i+", j:"+j+" "+lexicalCxns.get(j).getName());
test[j] = lexicalCxns.get(j); //input[i][j] = lexicalCxns.get(j);
}

int it = 0;
for (int l = input[i].length; l < copy.length; l++){
copy[l] = test[it];
it += 1;
}

input[i] = copy;

}catch (GrammarException g) {
System.out.println("Unknown input lexeme: " + utterance.getElement(i).getOrthography());

}

}

input[utterance.size()] = new Construction[1];
input[utterance.size()][0] = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,14 @@ T get(Construction cxn, int startIndex) {
a.getPossibleSemSpecs().setID();
return a;
}

// adds a new Construction to canonical Instances HashMap. @seantrott.
public void put(Construction cxn) {
T a = factory.get(cxn);
canonicalInstances.put(cxn, a); // factory.get(cxn));
//System.out.println(factory.get(cxn));

}

@SuppressWarnings("unchecked")
public T get(Construction cxn) {
Expand Down
2 changes: 1 addition & 1 deletion first/adj.grm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ construction Red
constraints
self.m.value <-- @red




26 changes: 22 additions & 4 deletions first/nominal-nouns.grm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ general construction SingularNoun
self.m.number <-- @singular
self.m.bounding <-- @determinate


/*
construction Block
subcase of SingularNoun
form
Expand All @@ -22,17 +22,22 @@ construction Block
constraints
self.m.ontological-category <-- @block
self.m.scale <-- @size

*/

construction BlockLemma
construction BlockLemmaNoun
subcase of Noun
constructional
constraints
self.features.number <-- "undetermined"
form
constraints
self.f.lemma <-- "block"
self.f.lemma <-- "block"
self.f.orth <-- "orth" // testing so it doesn't get picked up as lexicalCxn
meaning
constraints
self.m.ontological-category <-- @block
self.m.scale <-- @size
self.m.number <-- "undetermined"



Expand All @@ -46,6 +51,17 @@ construction Room
self.m.ontological-category <-- @room
self.m.scale <-- @size

construction RoomLemma
subcase of Noun
form
constraints
self.f.orth <-- "room"
self.f.lemma <-- "room"
meaning
constraints
self.m.ontological-category <-- @room
self.m.scale <-- @size

//
// Plural Count Nouns
//
Expand All @@ -60,6 +76,7 @@ general construction PluralNoun
self.m.number <-- @plural
self.m.bounding <-- @indeterminate

/*
construction Blocks
subcase of PluralNoun
form
Expand All @@ -68,6 +85,7 @@ construction Blocks
meaning
constraints
self.m.ontological-category <-- @block
*/

// Proper Nouns
general construction ProperNounNP
Expand Down
13 changes: 13 additions & 0 deletions first/nominal-pronoun.grm
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,16 @@ construction He
self.m.number <-- @singular
self.m.gender <-- @male

construction I-Pronoun
subcase of Pronoun, Singular, FirstPerson
constructional
constraints
self.features.case <-- "nom"
form
constraints
self.f.orth <-- "I"
meaning
constraints
self.m.ontological-category <-- @person
self.m.number <-- @singular
self.m.gender <-- @genderValues
2 changes: 2 additions & 0 deletions first/schemas-grammatical.grm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ schema WordForm
roles
orth
lemma
constraints
lemma <-- "test"


// REFERENT DESCRIPTOR (RD) schemas
Expand Down
13 changes: 13 additions & 0 deletions first/verb-lexicalverb.grm
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ construction MovePastParticiple
self.f.orth <-- "moved"


// testing lemma usage
construction BlockLemmaVerb
subcase of LexicalVerb
constructional
constraints
self.verbform <-- Present
form
constraints
self.f.orth <-- "orth" // testing so it doesn't get picked up as lexicalCxn
self.f.lemma <-- "block"
meaning
constraints
self.pf.tense <-- "undetermined"


general construction SeeT // 8/21/13 Transitive
Expand Down
Binary file added src/main/__pycache__/feature.cpython-34.pyc
Binary file not shown.
Binary file added src/main/__pycache__/utils.cpython-34.pyc
Binary file not shown.
Loading

0 comments on commit 4446351

Please sign in to comment.