/// <summary> /// Gets depeendencies from sentence. /// </summary> /// <param name="annotation"></param> /// <returns></returns> private NotenizerDependencies GetDepencencies(Annotation annotation) { Tree tree; NotenizerDependency dep; GrammaticalStructure gramStruct; NotenizerDependencies dependencies; NotenizerDependency nsubjComplement; TreebankLanguagePack treeBankLangPack; java.util.Collection typedDependencies; GrammaticalStructureFactory gramStructFact; tree = annotation.get(typeof(TreeCoreAnnotations.TreeAnnotation)) as Tree; treeBankLangPack = new PennTreebankLanguagePack(); gramStructFact = treeBankLangPack.grammaticalStructureFactory(); gramStruct = gramStructFact.newGrammaticalStructure(tree); typedDependencies = gramStruct.typedDependenciesCollapsed(); dependencies = new NotenizerDependencies(); foreach (TypedDependency typedDependencyLoop in (typedDependencies as java.util.ArrayList)) { dep = new NotenizerDependency(typedDependencyLoop); dependencies.Add(dep); if (dep.Relation.IsNominalSubject()) { nsubjComplement = new NotenizerDependency(typedDependencyLoop); nsubjComplement.TokenType = dep.TokenType == TokenType.Dependent ? TokenType.Governor : TokenType.Dependent; dependencies.Add(nsubjComplement); } } return dependencies; }
/// <summary> /// Create dependencies from deocument. /// </summary> /// <param name="dbEntry"></param> /// <param name="noteFieldName"></param> /// <returns></returns> private static NotenizerDependencies ParseDependencies(BsonDocument dbEntry, String noteFieldName) { int position; TokenType tokenType; NotenizerWord governor; NotenizerWord dependent; BsonDocument governorDoc; BsonDocument dependantDoc; NotenizerRelation relation; ComparisonType comparisonType; NotenizerDependency dependency; NotenizerDependencies dependencies = new NotenizerDependencies(); // foreach note dependency foreach (BsonDocument documentLoop in dbEntry[noteFieldName].AsBsonArray) { relation = new NotenizerRelation(documentLoop[DBConstants.RelationNameFieldName].AsString); // foreach dependency in array of dependencies with same relation name foreach (BsonDocument dependencyDocLoop in documentLoop[DBConstants.DependenciesFieldName].AsBsonArray) { governorDoc = dependencyDocLoop[DBConstants.GovernorFieldName].AsBsonDocument; dependantDoc = dependencyDocLoop[DBConstants.DependentFieldName].AsBsonDocument; position = dependencyDocLoop[DBConstants.PositionFieldName].AsInt32; comparisonType = dependencyDocLoop.GetValue(DBConstants.ComparisonTypeFieldName, ComparisonType.Unidentified).AsInt32.ToEnum<ComparisonType>(); tokenType = dependencyDocLoop.GetValue(DBConstants.TokenTypeFieldName, TokenType.Unidentified).AsInt32.ToEnum<TokenType>(); governor = new NotenizerWord( governorDoc[DBConstants.POSFieldName].AsString, governorDoc[DBConstants.IndexFieldName].AsInt32, governorDoc[DBConstants.LemmaFieldName].AsString, governorDoc[DBConstants.NERFieldName].AsString); dependent = new NotenizerWord( dependantDoc[DBConstants.POSFieldName].AsString, dependantDoc[DBConstants.IndexFieldName].AsInt32, dependantDoc[DBConstants.LemmaFieldName].AsString, dependantDoc[DBConstants.NERFieldName].AsString); dependency = new NotenizerDependency(governor, dependent, relation, position, comparisonType, tokenType); dependencies.Add(dependency); } } return dependencies; }