Skip to content

Commit

Permalink
Merge pull request #304 from rastaarh/UpdatedGeocodingParser
Browse files Browse the repository at this point in the history
Updated geocoding parser
  • Loading branch information
paween authored Jul 23, 2020
2 parents d27172e + be50f56 commit 37f3d36
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 48 deletions.
7 changes: 7 additions & 0 deletions libPhoneNumber-GeocodingParser/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
target 'libPhoneNumber-GeocodingParser' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!

# Pods for libPhoneNumber-GeocodingParser
pod 'SSZipArchive'
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,26 @@
objects = {

/* Begin PBXBuildFile section */
9439832424CA460700CF8CB4 /* SSZipArchive.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9439832324CA460700CF8CB4 /* SSZipArchive.framework */; };
9439832524CA460700CF8CB4 /* SSZipArchive.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9439832324CA460700CF8CB4 /* SSZipArchive.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
9478476B24BCD14D004F5637 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 9478476A24BCD14D004F5637 /* main.m */; };
9478477324BCD180004F5637 /* NBGeocoderMetadataParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 9478477224BCD180004F5637 /* NBGeocoderMetadataParser.m */; };
9478477624BCD1AB004F5637 /* NBSQLiteDatabaseConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 9478477524BCD1AB004F5637 /* NBSQLiteDatabaseConnection.m */; };
9BBB13F5268ECEF110BFB4A3 /* Pods_libPhoneNumber_GeocodingParser.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB42456B7D37F6CA481559F0 /* Pods_libPhoneNumber_GeocodingParser.framework */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
9439832624CA460700CF8CB4 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
9439832524CA460700CF8CB4 /* SSZipArchive.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
9478476524BCD14D004F5637 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -25,30 +39,56 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
1174FF265138ABDB2DE27F14 /* Pods-libPhoneNumber-GeocodingParser.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-libPhoneNumber-GeocodingParser.debug.xcconfig"; path = "Target Support Files/Pods-libPhoneNumber-GeocodingParser/Pods-libPhoneNumber-GeocodingParser.debug.xcconfig"; sourceTree = "<group>"; };
8FD4ACC3A7C4DC8DBDA891B2 /* Pods-libPhoneNumber-GeocodingParser.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-libPhoneNumber-GeocodingParser.release.xcconfig"; path = "Target Support Files/Pods-libPhoneNumber-GeocodingParser/Pods-libPhoneNumber-GeocodingParser.release.xcconfig"; sourceTree = "<group>"; };
9439832324CA460700CF8CB4 /* SSZipArchive.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SSZipArchive.framework; sourceTree = BUILT_PRODUCTS_DIR; };
9478476724BCD14D004F5637 /* libPhoneNumber-GeocodingParser */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "libPhoneNumber-GeocodingParser"; sourceTree = BUILT_PRODUCTS_DIR; };
9478476A24BCD14D004F5637 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
9478477124BCD180004F5637 /* NBGeocoderMetadataParser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NBGeocoderMetadataParser.h; sourceTree = "<group>"; };
9478477224BCD180004F5637 /* NBGeocoderMetadataParser.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NBGeocoderMetadataParser.m; sourceTree = "<group>"; };
9478477424BCD1AB004F5637 /* NBSQLiteDatabaseConnection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NBSQLiteDatabaseConnection.h; sourceTree = "<group>"; };
9478477524BCD1AB004F5637 /* NBSQLiteDatabaseConnection.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NBSQLiteDatabaseConnection.m; sourceTree = "<group>"; };
AB42456B7D37F6CA481559F0 /* Pods_libPhoneNumber_GeocodingParser.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_libPhoneNumber_GeocodingParser.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
9478476424BCD14D004F5637 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9BBB13F5268ECEF110BFB4A3 /* Pods_libPhoneNumber_GeocodingParser.framework in Frameworks */,
9439832424CA460700CF8CB4 /* SSZipArchive.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
019E1F2D6D2F2646AA0F7A07 /* Frameworks */ = {
isa = PBXGroup;
children = (
9439832324CA460700CF8CB4 /* SSZipArchive.framework */,
AB42456B7D37F6CA481559F0 /* Pods_libPhoneNumber_GeocodingParser.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
81942256806B519825D98257 /* Pods */ = {
isa = PBXGroup;
children = (
1174FF265138ABDB2DE27F14 /* Pods-libPhoneNumber-GeocodingParser.debug.xcconfig */,
8FD4ACC3A7C4DC8DBDA891B2 /* Pods-libPhoneNumber-GeocodingParser.release.xcconfig */,
);
path = Pods;
sourceTree = "<group>";
};
9478475E24BCD14D004F5637 = {
isa = PBXGroup;
children = (
9478476924BCD14D004F5637 /* libPhoneNumber-GeocodingParser */,
9478476824BCD14D004F5637 /* Products */,
81942256806B519825D98257 /* Pods */,
019E1F2D6D2F2646AA0F7A07 /* Frameworks */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -79,9 +119,12 @@
isa = PBXNativeTarget;
buildConfigurationList = 9478476E24BCD14D004F5637 /* Build configuration list for PBXNativeTarget "libPhoneNumber-GeocodingParser" */;
buildPhases = (
78E19583AC36ED362B40DB2E /* [CP] Check Pods Manifest.lock */,
9478476324BCD14D004F5637 /* Sources */,
9478476424BCD14D004F5637 /* Frameworks */,
9478476524BCD14D004F5637 /* CopyFiles */,
9439832224CA428D00CF8CB4 /* ShellScript */,
9439832624CA460700CF8CB4 /* Embed Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -124,6 +167,48 @@
};
/* End PBXProject section */

/* Begin PBXShellScriptBuildPhase section */
78E19583AC36ED362B40DB2E /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputFileListPaths = (
);
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-libPhoneNumber-GeocodingParser-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
9439832224CA428D00CF8CB4 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "# Type a script or drag a script file from your workspace to insert its path.\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
9478476324BCD14D004F5637 /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down Expand Up @@ -249,7 +334,9 @@
};
9478476F24BCD14D004F5637 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 1174FF265138ABDB2DE27F14 /* Pods-libPhoneNumber-GeocodingParser.debug.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 973LHT5R86;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -259,7 +346,9 @@
};
9478477024BCD14D004F5637 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 8FD4ACC3A7C4DC8DBDA891B2 /* Pods-libPhoneNumber-GeocodingParser.release.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 973LHT5R86;
ENABLE_HARDENED_RUNTIME = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,6 @@
ReferencedContainer = "container:libPhoneNumber-GeocodingParser.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "/Users/rastaar/Documents/geocoding"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "/Users/rastaar/Desktop"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
122 changes: 84 additions & 38 deletions libPhoneNumber-GeocodingParser/libPhoneNumber-GeocodingParser/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,106 @@

#import <Foundation/Foundation.h>
#import "NBGeocoderMetadataParser.h"
#import "SSZipArchive.h"

int main(int argc, const char *argv[]) {
@autoreleasepool {
if (argc != 3) {
NSLog(@"The libPhoneNumber-iOS Geocoder Parser requires two input arguments to properly "
if (argc != 2) {
NSLog(@"The libPhoneNumber-iOS Geocoder Parser requires 1 input arguments to properly "
@"function.");
NSLog(@"1. The complete folder path where the libPhoneNumber geocoding resource folder "
@"(found at: https://github.com/google/libphonenumber/tree/master/resources/geocoding) "
@"is stored on disk.");
NSLog(@"2. The complete directory path to the desired location to store the corresponding "
NSLog(@"1. The complete directory path to the desired location to store the corresponding "
@"SQLite databases created.");
NSLog(@"Example arguments: Users/JohnDoe/Documents/geocoding Users/JohnDoe/Desktop");
NSLog(@"Example argument: Users/JohnDoe/Desktop");
} else {
NSString *geocodingMetadataDirectory = @(argv[1]);
NSURL *databaseDesiredLocation = [NSURL fileURLWithPath:@(argv[2])];
NBGeocoderMetadataParser *metadataParser =
[[NBGeocoderMetadataParser alloc] initWithDestinationPath:[databaseDesiredLocation copy]];
// Download zip file from GitHub.
NSString *repositoryString = @"https://github.com/google/libphonenumber/archive/master.zip";
NSURL *databaseDesiredLocation = [NSURL fileURLWithPath:@(argv[1])];
NSURL *libPhoneNumberRepoURL = [NSURL URLWithString:repositoryString];

NSLog(@"Downloading geocoding metadata files from %@", repositoryString);
NSData *libPhoneNumberData = [NSData dataWithContentsOfURL:libPhoneNumberRepoURL];
NSLog(@"Downloaded geocoding metadata files.");

// Gather the documents directory path
NSString *temporaryDirectoryPath = NSTemporaryDirectory();
NSString *zipFilePath =
[temporaryDirectoryPath stringByAppendingPathComponent:@"/libPhoneNumber-iOS.zip"];
zipFilePath = [zipFilePath stringByStandardizingPath];
[libPhoneNumberData writeToFile:zipFilePath atomically:YES];
NSLog(@"Attempting to unzip downloaded metadata.");

// Unzip libphonenumber-master project using SSZipArchive library.
[SSZipArchive unzipFileAtPath:zipFilePath toDestination:temporaryDirectoryPath];
NSLog(@"Successfully unzipped metadata files.");

// Navigate through project to geocoding metadata resource files.
NSString *libPhoneNumberFolderPath =
[NSString stringWithFormat:@"%@/libphonenumber-master", temporaryDirectoryPath];
NSError *error;
NSArray *languages =
[[NSFileManager defaultManager] contentsOfDirectoryAtPath:geocodingMetadataDirectory
NSArray *filesInDirectory =
[[NSFileManager defaultManager] contentsOfDirectoryAtPath:libPhoneNumberFolderPath
error:&error];
if (error != NULL) {
NSLog(@"Error occurred when trying to read directory: %@"
@"Error message: %@",
geocodingMetadataDirectory, [error localizedDescription]);
if (error != nil) {
NSLog(@"An error occurred when attempting to access files in repository. Error message: %@",
error.description);
return 1;
}
NSArray *textFilesAvailable;
NSString *languageFolderPath;
for (NSString *language in languages) {
NSLog(@"Creating SQLite database file for the language: %@", language);
languageFolderPath =
[NSString stringWithFormat:@"%@/%@", geocodingMetadataDirectory, language];
textFilesAvailable =
[[NSFileManager defaultManager] contentsOfDirectoryAtPath:languageFolderPath
if ([filesInDirectory containsObject:@"resources"]) {
NSString *resourcesFolderPath =
[NSString stringWithFormat:@"%@/resources", libPhoneNumberFolderPath];
filesInDirectory =
[[NSFileManager defaultManager] contentsOfDirectoryAtPath:resourcesFolderPath
error:&error];
if (error != NULL) {
NSLog(@"Error occurred when trying to read files for the language directory: %@",
languageFolderPath);
error = NULL;
continue;
NSLog(@"An error occurred when attempting to access files in project's 'resources' "
@"folder. Error message: %@",
error.description);
return 1;
}
for (NSString *filename in textFilesAvailable) {
NSString *extension = [[filename pathExtension] lowercaseString];
if ([filesInDirectory containsObject:@"geocoding"]) {
NSString *geocodingFolderPath =
[NSString stringWithFormat:@"%@/geocoding", resourcesFolderPath];
NSArray *languages =
[[NSFileManager defaultManager] contentsOfDirectoryAtPath:geocodingFolderPath
error:&error];
if (error != NULL) {
NSLog(@"An error occurred when attempting to access files in project's 'geocoding' "
@"folder. Error message: %@",
error.description);
return 1;
}
NBGeocoderMetadataParser *metadataParser = [[NBGeocoderMetadataParser alloc]
initWithDestinationPath:[databaseDesiredLocation copy]];

NSArray *textFilesAvailable;
NSString *languageFolderPath;
for (NSString *language in languages) {
NSLog(@"Creating SQLite database file for the language: %@", language);
languageFolderPath =
[NSString stringWithFormat:@"%@/%@", geocodingFolderPath, language];
textFilesAvailable =
[[NSFileManager defaultManager] contentsOfDirectoryAtPath:languageFolderPath
error:&error];
if (error != NULL) {
NSLog(@"Error occurred when trying to read files for the language directory: %@",
languageFolderPath);
error = NULL;
continue;
}
for (NSString *filename in textFilesAvailable) {
NSString *extension = [[filename pathExtension] lowercaseString];

if ([extension isEqualToString:@"txt"]) {
NSString *completeFilePath =
[NSString stringWithFormat:@"%@/%@", languageFolderPath, filename];
[metadataParser convertFileToSQLiteDatabase:completeFilePath
withFileName:filename
withLanguage:language];
if ([extension isEqualToString:@"txt"]) {
NSString *completeFilePath =
[NSString stringWithFormat:@"%@/%@", languageFolderPath, filename];
[metadataParser convertFileToSQLiteDatabase:completeFilePath
withFileName:filename
withLanguage:language];
}
}
NSLog(@"Created SQLite database file for the language: %@", language);
}
}
NSLog(@"Created SQLite database file for the language: %@", language);
}
}
}
Expand Down

0 comments on commit 37f3d36

Please sign in to comment.