Skip to content

Commit

Permalink
stupid nsinteger error (make sure it's not a pointer)
Browse files Browse the repository at this point in the history
  • Loading branch information
ciniglio committed Dec 25, 2009
1 parent 8247913 commit 1fab109
Show file tree
Hide file tree
Showing 25 changed files with 1,070 additions and 241 deletions.
2 changes: 1 addition & 1 deletion Info.plist
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleVersion</key>
<string>15D</string>
<string>186</string>
<key>QSDefaultsTemplate</key>
<dict>
<key>interface.bindingname</key>
Expand Down
4 changes: 2 additions & 2 deletions NLParser.h
Expand Up @@ -24,7 +24,7 @@
NSMutableDictionary *verbSynonyms;
NSMutableArray *possibleActions;

int actionLocation;
NSInteger actionLocation;
int directObjectLocation;
int prepositionLocation;
int indirectObjectLocation;
Expand All @@ -45,7 +45,7 @@
@property (nonatomic, retain) NSMutableArray *possibleActions;


@property int actionLocation;
@property (nonatomic, assign) NSInteger actionLocation;
@property int directObjectLocation;
@property int prepositionLocation;
@property int indirectObjectLocation;
Expand Down
39 changes: 31 additions & 8 deletions NLParser.m
Expand Up @@ -22,6 +22,9 @@ @implementation NLParser
@synthesize nounSynonyms;
@synthesize verbSynonyms;

@synthesize possibleNouns;
@synthesize possibleActions;

-(id)initWithRaw:(NSString *)rawInput
withPossibleNouns:(NSMutableArray *)pNouns
andWithPossibleActions:(NSMutableArray *)pActions{
Expand All @@ -32,7 +35,7 @@ -(id)initWithRaw:(NSString *)rawInput
verbSynonyms = [[NSMutableDictionary dictionary] retain];
possibleNouns = [pNouns retain];
possibleActions = [pActions retain];
actionLocation = -1;
[self setActionLocation:-1];
action = nil;
actionRemainder = nil;
verb = nil;
Expand All @@ -57,8 +60,10 @@ -(NSString *)makeLowercaseAndPunctuationFree:(NSString *)ugly {
}

-(float)actionProbable{
NSLog(@"started actionProbable");
int correct = 0;
NSArray *parts = [[self makeLowercaseAndPunctuationFree:action] componentsSeparatedByString:@" "];

int possible = [parts count];
for (NSString *part in parts){
//
Expand Down Expand Up @@ -122,26 +127,29 @@ - (int)getMostLikelyAction {
// iterate through each possible action
for (i=0;i < [actions count]; i++){
NSString *actName = [actions objectAtIndex:i];
NSString *act = [self makeLowercaseAndPunctuationFree:actName];
NSString *act = [[self makeLowercaseAndPunctuationFree:actName] retain];
NSArray *actionParts = [act componentsSeparatedByString:@" "];
NSString *mainAct = [actionParts objectAtIndex:0]; // assumes the verb is the first word in the action
NSRange range = [raw rangeOfString:mainAct];

if ([self getMatchScoreUsing:act] > bestScore && range.location != NSNotFound) {
if (range.location <= min){
ret = i;
action = actName;
verb = mainAct;
action = [actName retain];
verb = [mainAct retain];
min = range.location;
actionLocation = min;
bestScore = [self getMatchScoreUsing:act];
actionRemainder = [self cleanupWhitespaceIn:[raw substringFromIndex:(min + [mainAct length])]];
actionRemainder = [[self cleanupWhitespaceIn:[raw substringFromIndex:(min + [mainAct length])]] retain];
}
}
}
NSLog(@"ActionLocation : %d", actionLocation);
NSLog(@"Action remainder: %@", actionRemainder);
if ([self actionProbable] > .7)
return ret;
if ([self actionProbable] > .7){
NSLog(@"actionprobable done");
return ret;
}
return -1;
}

Expand All @@ -163,8 +171,18 @@ - (void)setObjectsWithIndirect:(BOOL)indirect {
if (prepositionLocation > 0) {
NSArray *rawArray = [raw componentsSeparatedByString:@" "];
NSRange doRange;
doRange.location = actionLocation + [[[action componentsSeparatedByString:@" "] objectAtIndex:0] length];
NSString *mainAct = [[action componentsSeparatedByString:@" "] objectAtIndex:0];
NSInteger mainActLength = [mainAct length];
NSInteger actionLoc = actionLocation;
NSInteger four = 4; int z = 0;
NSLog(@"suspicious: %d", four + z);

NSLog(@"sowi: actionLoc: %d", [self actionLocation] + mainActLength);
doRange.location = actionLocation + mainActLength;
NSLog(@"sowi: doRangeLoc: %d", doRange.location);
NSLog(@"sowi: prerpLoc: %d", prepositionLocation);
doRange.length = prepositionLocation - doRange.location;
NSLog(@"sowi: doranglen: %d", doRange.length);
directObject = [self cleanupWhitespaceIn:[raw substringWithRange:doRange]];//[[rawArray subarrayWithRange:doRange] componentsJoinedByString:@""];
directObjectLocation = doRange.location + 1;

Expand Down Expand Up @@ -272,6 +290,11 @@ - (BOOL) handleSynonyms {
return (noun || verb);
}

- (void) parseVerbSynonyms {
NSString *targetString = [raw substringToIndex:actionLocation];
NSLog (@"target: %@", targetString);
}

- (NSString *) pathForSynonymsDataFile
{
NSFileManager *fileManager = [NSFileManager defaultManager];
Expand Down
5 changes: 4 additions & 1 deletion NL_interface.m
Expand Up @@ -74,11 +74,14 @@ - (IBAction) findActions:(id)sender{
}
int likelyIndex = [nlp getMostLikelyAction];
QSAction *likelyAction = [possibleActions objectAtIndex:likelyIndex];
// [nlp parseVerbSynonyms];
BOOL indirect = [likelyAction argumentCount] == 1 ? NO : YES;
[nlp findAndSetPreposition];
[nlp setObjectsWithIndirect:indirect];

NSLog(@"past LA2");
// Logging
NSLog(@"Most Likely: %@ ", [likelyAction name]);
NSLog(@"Most Likely: %@, %@", [likelyAction name], [nlp actionLocation]);
NSLog(@"Most Likely: %@, %@, %d", [likelyAction name], [nlp actionLocation], [likelyAction argumentCount]);
NSLog(@"Preposition: %@", [nlp preposition]);
NSLog(@"DO: %@ // IO: %@", [nlp directObject], [nlp indirectObject]);
Expand Down

0 comments on commit 1fab109

Please sign in to comment.