Mercurial > hip
changeset 8:11a051a31077
Now even if a preposition is matched, the suggestion list will include the sentence where that preposition is left unmatched (treated as part of the direct object), just in case that's what the user wants.
author | jonathandicarlo@jonathan-dicarlos-macbook-pro.local |
---|---|
date | Wed, 14 May 2008 15:06:17 -0700 |
parents | aab0d14248f5 |
children | d5699c104b48 |
files | hip.js |
diffstat | 1 files changed, 24 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/hip.js Wed May 14 14:59:24 2008 -0700 +++ b/hip.js Wed May 14 15:06:17 2008 -0700 @@ -145,7 +145,9 @@ var x; var suggestions = []; var completions = []; + var newFilledMods = {}; var directObject = ""; + var newCompletions = []; if ( dictKeys( unfilledMods ).length == 0 ) { // Done with modifiers, try to parse direct object. if ( unusedWords.length == 0 ) { @@ -195,33 +197,39 @@ } } } - if ( matchIndices.length == 0 ) { - // no match for this preposition. - // Leave it blank and try to parse the rest: - var newFilledMods = dictDeepCopy( filledMods ); - newFilledMods[preposition] = ""; - var directObject = unusedWords.join( " " ); - return this.recursiveParse( unusedWords, newFilledMods, newUnfilledMods ); - } else { - // this is placeholder, destroy it. + + // If no match was found, all we'll return is one sentence formed by + // leaving that preposition blank. But even if a match was found, we + // still want to include this sentence as a possibility. + newFilledMods = dictDeepCopy( filledMods ); + newFilledMods[preposition] = ""; + directObject = unusedWords.join( " " ); + newCompletions = this.recursiveParse( unusedWords, + newFilledMods, + newUnfilledMods ); + completions = completions.concat( newCompletions ); + + if ( matchIndices.length > 0 ) { + // Sentences that can be formed by using the match(es) for this + // preposition. for ( x in matchIndices ) { var noun = unusedWords[ matchIndices[x]+1 ]; var newUnusedWords = unusedWords.slice(); newUnusedWords.splice( matchIndices[x], 2 ); - var directObject = newUnusedWords.join( " " ); + directObject = newUnusedWords.join( " " ); suggestions = nounType.suggest( noun ); for ( var y in suggestions ) { - var newFilledMods = dictDeepCopy( filledMods ); + newFilledMods = dictDeepCopy( filledMods ); newFilledMods[ preposition ] = suggestions[y]; - var newCompletions = this.recursiveParse( newUnusedWords, - newFilledMods, - newUnfilledMods ); + newCompletions = this.recursiveParse( newUnusedWords, + newFilledMods, + newUnfilledMods ); completions = completions.concat( newCompletions ); } } - return completions; - } + } + return completions; } }, @@ -538,6 +546,4 @@ /* Minor problems: 2. multiple word direct objects are truncated to single word -5. Need to include the suggestion where matched prepositions aren't used but - are treated as part of the direct object instead. */