Skip to content

Instantly share code, notes, and snippets.

@reisepass
Last active December 17, 2015 15:19
Show Gist options
  • Save reisepass/5631031 to your computer and use it in GitHub Desktop.
Save reisepass/5631031 to your computer and use it in GitHub Desktop.
Here is an example use case for the wildcard.
protected ArrayList<String> wildWithInpAtBack(String inp,int ngramLength){
ArrayList<String> out = new ArrayList<String>(ngramLength);
for(int i=0;i<ngramLength-1;i++){
out.add(i, FirstSentSum.WILDCARD_STRING);
}
if(inp.indexOf(" ")!=-1){
for(String sepI : inp.split(" ")){
out.add(sepI);
}
}
else
out.add(ngramLength-1, inp);
return out;
}
private useWildcard(){ // Or here is a better example. I simply fill the rest of this sentence with ngrams that link together
String[] wordsSoFar = strBld.toString().split(" ");
String justAdded= wordsSoFar[wordsSoFar.length-1];
while( strBld.length()<sumLeng ){
for(Map.Entry<ArrayList<String>, Double> elem : list){ // OMG This may read through the entire library
if(elem.getKey().size()>1){
if(localCompareObj.compare(elem.getKey(),wildWithInpAtFront(justAdded))==0){
elem.getKey().remove(0);// If we dont do this then the TopNE[0] will appear twice
strBld.append(printArray(elem.getKey()));
wordsSoFar = strBld.toString().split(" ");
justAdded= wordsSoFar[wordsSoFar.length-1];
}
}
}
strBld.append(" ");
if(strBld.length()>sumLeng){ //Remove words that done fit and we are done
out = strBld.toString();
out = out.substring(0,sumLeng-1);
out = out.substring(0,out.lastIndexOf(" "));
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment