// collapseMultiwordPreps(list); private static void CollapsePrepAndPoss(ICollection <TypedDependency> list) { ICollection <TypedDependency> newTypedDeps = new List <TypedDependency>(); // Construct a map from words to the set of typed // dependencies in which the word appears as governor. IDictionary <IndexedWord, ICollection <TypedDependency> > map = Generics.NewHashMap(); foreach (TypedDependency typedDep in list) { if (!map.Contains(typedDep.Gov())) { map[typedDep.Gov()] = Generics.NewHashSet <TypedDependency>(); } map[typedDep.Gov()].Add(typedDep); } //log.info("here's the map: " + map); foreach (TypedDependency td1 in list) { if (td1.Reln() != GrammaticalRelation.Kill) { IndexedWord td1Dep = td1.Dep(); string td1DepPOS = td1Dep.Tag(); // find all other typedDeps having our dep as gov ICollection <TypedDependency> possibles = map[td1Dep]; if (possibles != null) { // look for the "second half" foreach (TypedDependency td2 in possibles) { // TreeGraphNode td2Dep = td2.dep(); // String td2DepPOS = td2Dep.parent().value(); if (td1.Reln() == GrammaticalRelation.Dependent && td2.Reln() == GrammaticalRelation.Dependent && td1DepPOS.Equals("P")) { GrammaticalRelation td3reln = UniversalChineseGrammaticalRelations.ValueOf(td1Dep.Value()); if (td3reln == null) { td3reln = GrammaticalRelation.ValueOf(Language.UniversalChinese, td1Dep.Value()); } TypedDependency td3 = new TypedDependency(td3reln, td1.Gov(), td2.Dep()); //log.info("adding: " + td3); newTypedDeps.Add(td3); td1.SetReln(GrammaticalRelation.Kill); // remember these are "used up" td2.SetReln(GrammaticalRelation.Kill); } } // remember these are "used up" // Now we need to see if there any TDs that will be "orphaned" // by this collapse. Example: if we have: // dep(drew, on) // dep(on, book) // dep(on, right) // the first two will be collapsed to on(drew, book), but then // the third one will be orphaned, since its governor no // longer appears. So, change its governor to 'drew'. if (td1.Reln().Equals(GrammaticalRelation.Kill)) { foreach (TypedDependency td2_1 in possibles) { if (!td2_1.Reln().Equals(GrammaticalRelation.Kill)) { //log.info("td1 & td2: " + td1 + " & " + td2); td2_1.SetGov(td1.Gov()); } } } } } } // now copy remaining unkilled TDs from here to new foreach (TypedDependency td in list) { if (!td.Reln().Equals(GrammaticalRelation.Kill)) { newTypedDeps.Add(td); } } list.Clear(); // forget all (esp. killed) TDs Sharpen.Collections.AddAll(list, newTypedDeps); }
public UniversalChineseGrammaticalStructure(Tree t, IPredicate <string> puncFilter, IHeadFinder hf) : base(t, UniversalChineseGrammaticalRelations.Values(), UniversalChineseGrammaticalRelations.ValuesLock(), null, hf, puncFilter, Filters.AcceptFilter()) { }