[sword-svn] r3407 - in trunk/bindings/objc: src test

mdbergmann at crosswire.org mdbergmann at crosswire.org
Mon Feb 15 07:12:37 MST 2016


Author: mdbergmann
Date: 2016-02-15 07:12:36 -0700 (Mon, 15 Feb 2016)
New Revision: 3407

Modified:
   trunk/bindings/objc/src/SwordModule.h
   trunk/bindings/objc/src/SwordModule.mm
   trunk/bindings/objc/test/SwordModuleTest.m
Log:
added code for retrieving strong's numbers in a normalized format (padded to 5 digits), plus tests.

Modified: trunk/bindings/objc/src/SwordModule.h
===================================================================
--- trunk/bindings/objc/src/SwordModule.h	2016-02-15 10:12:50 UTC (rev 3406)
+++ trunk/bindings/objc/src/SwordModule.h	2016-02-15 14:12:36 UTC (rev 3407)
@@ -292,6 +292,7 @@
 - (NSString *)entryAttributeValueFootnoteOfType:(NSString *)fnType indexValue:(NSString *)index forKey:(SwordKey *)aKey;
 
 - (NSArray *)entryAttributeValuesLemma;
+- (NSArray *)entryAttributeValuesLemmaNormalized;
 
 // ----------------- Module text access ----------------------
 

Modified: trunk/bindings/objc/src/SwordModule.mm
===================================================================
--- trunk/bindings/objc/src/SwordModule.mm	2016-02-15 10:12:50 UTC (rev 3406)
+++ trunk/bindings/objc/src/SwordModule.mm	2016-02-15 14:12:36 UTC (rev 3407)
@@ -135,10 +135,6 @@
     return self;
 }
 
-- (void)dealloc {
-//    ALog(@"");
-}
-
 #pragma mark - Filters
 
 - (void)addRenderFilter:(SwordFilter *)aFilter {
@@ -547,7 +543,7 @@
 - (NSArray *)entryAttributeValuesLemma {
     NSMutableArray *array = [NSMutableArray array];
     
-    swModule->stripText(); // force processing of key
+    swModule->stripText(); // force processing of key, if it hasn't been done already
     
     // parse entry attributes and look for Lemma (Strong's numbers)
     sword::AttributeTypeList::iterator words;
@@ -574,6 +570,49 @@
     return [NSArray arrayWithArray:array];
 }
 
+- (NSArray *)entryAttributeValuesLemmaNormalized {
+    NSArray *lemmas = [self entryAttributeValuesLemma];
+    // post process all codes and mormalize the number
+    // Hebrew keys should have 5 number digits
+    NSMutableArray *buf = [NSMutableArray array];
+    for(NSString *lemma in lemmas) {
+        // Hebrew
+        NSString *prefix = nil;
+        if([lemma hasPrefix:@"H"]) {
+            prefix = @"H";
+        }
+        if([lemma hasPrefix:@"G"]) {
+            prefix = @"G";
+        }
+        
+        if(prefix == nil) {
+            // add as is
+            [buf addObject:lemma];
+            
+        } else {
+            // lemma may contain more codes concatenated by space
+            NSArray *keys = [lemma componentsSeparatedByString:@" "];
+            for(__strong NSString *key in keys) {
+                // trim
+                key = [key stringByReplacingOccurrencesOfString:@" " withString:@""];
+                NSArray *keyComps = [key componentsSeparatedByString:prefix];
+                if(keyComps.count == 2) {
+                    NSString *keyValue = keyComps[1];
+                    if(keyValue.length < 5) {
+                        NSInteger pad = 5 - keyValue.length;
+                        for(int i = 0;i < pad;i++) {
+                            keyValue = [NSString stringWithFormat:@"0%@", keyValue];
+                        }
+                    }
+                    // add to result array
+                    [buf addObject:[NSString stringWithFormat:@"%@%@", prefix, keyValue]];
+                }
+            }
+        }
+    }
+    return [NSArray arrayWithArray:buf];
+}
+
 - (NSString *)entryAttributeValuePreverseForKey:(SwordKey *)aKey {
     [self.moduleLock lock];
     [self setSwordKey:aKey];

Modified: trunk/bindings/objc/test/SwordModuleTest.m
===================================================================
--- trunk/bindings/objc/test/SwordModuleTest.m	2016-02-15 10:12:50 UTC (rev 3406)
+++ trunk/bindings/objc/test/SwordModuleTest.m	2016-02-15 14:12:36 UTC (rev 3407)
@@ -83,7 +83,7 @@
     XCTAssertTrue([[text text] containsString:@"But he answered and said, <font color=\"red\"> It is written, Man shall not live by bread alone, but by every word that proceedeth out of the mouth of God.</font>"]);
 }
 
-- (void)testStrongsNumberRetrieval {
+- (void)testStrongsNumberHebrewRetrieval {
     SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"KJV"];
     XCTAssertNotNil(bible, @"Module is nil");
 
@@ -96,6 +96,45 @@
     XCTAssertTrue([@"H07225,H0430,H0853 H01254,H08064,H0853,H0776" isEqualToString:combinedString]);
 }
 
+- (void)testStrongsNumberHebrewNormalizedRetrieval {
+    SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"KJV"];
+    XCTAssertNotNil(bible, @"Module is nil");
+    
+    [bible setKeyString:@"Gen 1:1"];
+    NSArray *strongsNumbers = [bible entryAttributeValuesLemmaNormalized];
+    XCTAssertTrue(strongsNumbers != nil);
+    XCTAssertTrue([strongsNumbers count] > 0);
+    NSString *combinedString = [strongsNumbers componentsJoinedByString:@","];
+    NSLog(@"%@", combinedString);
+    XCTAssertTrue([@"H07225,H00430,H00853,H01254,H08064,H00853,H00776" isEqualToString:combinedString]);
+}
+
+- (void)testStrongsNumberGreekRetrieval {
+    SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"KJV"];
+    XCTAssertNotNil(bible, @"Module is nil");
+    
+    [bible setKeyString:@"Mat 1:1"];
+    NSArray *strongsNumbers = [bible entryAttributeValuesLemma];
+    XCTAssertTrue(strongsNumbers != nil);
+    XCTAssertTrue([strongsNumbers count] > 0);
+    NSString *combinedString = [strongsNumbers componentsJoinedByString:@","];
+    NSLog(@"%@", combinedString);
+    XCTAssertTrue([@"G976,G1078,G2424,G5547,G5207,G1138,G5207,G11" isEqualToString:combinedString]);
+}
+
+- (void)testStrongsNumberGreekNormalizedRetrieval {
+    SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"KJV"];
+    XCTAssertNotNil(bible, @"Module is nil");
+    
+    [bible setKeyString:@"Mat 1:1"];
+    NSArray *strongsNumbers = [bible entryAttributeValuesLemmaNormalized];
+    XCTAssertTrue(strongsNumbers != nil);
+    XCTAssertTrue([strongsNumbers count] > 0);
+    NSString *combinedString = [strongsNumbers componentsJoinedByString:@","];
+    NSLog(@"%@", combinedString);
+    XCTAssertTrue([@"G00976,G01078,G02424,G05547,G05207,G01138,G05207,G00011" isEqualToString:combinedString]);
+}
+
 - (void)testFirstBookNTIntroGer {
     SwordBible *bible = (SwordBible *)[mgr moduleWithName:@"GerNeUe"];
 




More information about the sword-cvs mailing list