/// <summary> /// Determines whether the given PhraseNode overlaps with the given word. /// The two overlap if the last word of the phrase is the same as the given word, /// or if the second-to-last word of the phrase is the same as the given word and the last word of the phrase is ignorable. /// </summary> /// <param name="name">The phrase to check for overlap.</param> /// <param name="word">The word to check for overlap with.</param> /// <returns>True if the phrase and word overlap, False otherwise.</returns> private bool HasOverlap(PhraseNode name, string word) { if (name == null || name.Size() == 0 || string.IsNullOrEmpty(word)) { return(false); } bool hasOverlap = false; if (string.Equals(name.LastWord().Text, word, StringComparison.InvariantCultureIgnoreCase)) { //last word of name is same as given word hasOverlap = true; } else if (name.Size() > 1) { if (string.Equals(name[name.Size() - 2].Text, word, StringComparison.InvariantCultureIgnoreCase) && PosData.IsIgnorableHeadWord(name.LastWord().Text)) { //second-to-last word of name is same as given word, and the last word of name is ignorable hasOverlap = true; } } return(hasOverlap); }
/// <summary> /// Determines whether the given phrase indicates an event handler method. /// </summary> /// <param name="parsedName">The PhraseNode to test.</param> /// <returns>True if the phrase indicates an event handler method, False otherwise.</returns> protected bool IsEventHandler(PhraseNode parsedName) { if (parsedName == null || parsedName.Size() == 0) { return(false); } else { return(IsNonBaseVerb(parsedName.LastWord().Text) && parsedName[0].Text.ToLower() != "get" && parsedName[0].Text.ToLower() != "set"); } }
/// <summary> /// Checks for semantic overlaps between parts of the given method's name and its UnknownArguments. /// If overlaps are found, appropriate EquivalenceNodes are created. /// </summary> /// <param name="mdn">The MethodDeclarationNode to check for overlaps.</param> /// <param name="checkDO">Indicates whether the Direct Object was taken from the method name, and therefore the Theme must be checked for overlap with UnknownArguments.</param> /// <param name="checkIO">Indicates whether the Indirect Object was taken from the method name, and therefore the SecondaryArguments must be checked for overlap with UnknownArguments.</param> private void CheckOverlap(MethodDeclarationNode mdn, bool checkDO, bool checkIO) { if (mdn.ParsedName[0].Text.ToLower() == "set") { return; //special case } PhraseNode theme = null; ArgumentNode arg = null; //get DO word from name string wordDO = ""; if (checkDO) //theme is in the method name { theme = (PhraseNode)mdn.Theme; wordDO = theme.LastWord().Text; } //get IO word from name string wordIO = ""; if (checkIO) //IO is in the method name { arg = mdn.SecondaryArguments[0]; PhraseNode argn = (PhraseNode)arg.Argument; wordIO = argn.LastWord().Text; if (wordDO == wordIO) { return; //no equivalence if multiple overlap } } //find overlap List <Node> unknownArgs = mdn.UnknownArguments; List <Node> DOOverlappingArgs = new List <Node>(); List <Node> IOOverlappingArgs = new List <Node>(); for (int i = 0; i < unknownArgs.Count; i++) { if (unknownArgs[i] is VariableDeclarationNode) { VariableDeclarationNode var = (VariableDeclarationNode)unknownArgs[i]; PhraseNode name = var.ParsedName; PhraseNode type = var.Type.ParsedName; bool DOOverlaps = false; bool IOOverlaps = false; if (checkDO) { DOOverlaps = HasOverlap(name, wordDO) || HasOverlap(type, wordDO); if (DOOverlaps) { DOOverlappingArgs.Add(unknownArgs[i]); } } if (checkIO) { IOOverlaps = HasOverlap(name, wordIO) || HasOverlap(type, wordIO); if (IOOverlaps) { IOOverlappingArgs.Add(unknownArgs[i]); } } if (DOOverlaps && IOOverlaps) { return; //no equivalence if multiple overlap } } } //Create overlap in SWUM if (DOOverlappingArgs.Count > 0) { EquivalenceNode en = mdn.CreateEquivalenceFromUnknownArguments(theme, DOOverlappingArgs); mdn.Theme = en; //reset theme in MethodDeclarationNode to new equivalence node } if (IOOverlappingArgs.Count > 0) { EquivalenceNode en = mdn.CreateEquivalenceFromUnknownArguments(arg.Argument, IOOverlappingArgs); arg.Argument = en; //reset mdn.SecondaryArguments to point to new equivalence node } }