Created
January 23, 2015 00:10
-
-
Save atduskgreg/bf7e9439b007b2ecb304 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sentence1 = "Yemeni Government Collapses as President and Prime Minister Resign"; | |
var sentence2 = "Diversity in play as Sundance Film Festival kicks off in Park City"; | |
var tags1 = Tools.tagPos(sentence1); | |
var tags2 = Tools.tagPos(sentence2); | |
function findProperNounPhrase(tags){ | |
var previousTag = ""; | |
var properNounPhrase = ""; | |
for(var i = 0; i < tags.length; i++){ | |
if(tags[i].pos == "NNP" || tags[i].pos == "JJ"){ | |
if(previousTag == "NNP" || previousTag == "JJ"){ | |
properNounPhrase += " " + tags[i].word; | |
} else { | |
properNounPhrase = tags[i].word; | |
} | |
} else { | |
if(properNounPhrase.length > 0){ | |
break; | |
} | |
} | |
previousTag = tags[i].pos; | |
} | |
return properNounPhrase; | |
} | |
var pn1 = findProperNounPhrase(tags1); | |
var pn2 = findProperNounPhrase(tags2); | |
var newSentence = sentence1.replace(pn1, pn2); | |
console.log(newSentence); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment