4 Functions to use GeograPy¶
The class isC3GP is available to process string data for locational information. It is built on the GeoGrapy library.
4.1 Use of object¶
A number of functions were added to support the use of the GeoGrapy package. This class can be used to create the object.
- class geolocation.isC3GP¶
Object that uses geograpy
An instance of this class is created with
- isC3GP.__init__()¶
with each string containing a potential location, it can be loaded with this method.
- isC3GP.loadrawGP()¶
Loads record for further analysis
- Parameters
rawtext – A string of text of be analyzed
4.2 Boolean indicators for country¶
Now for the C3 case the locations will be Canadian, US and Rest of World.
4.2.1 Canada¶
Once loadraw has analyzed the text
- isC3GP.isCanC3GP()¶
returns boolean if Canada
4.2.2 United States¶
- isC3GP.isUSC3GP()¶
returns boolean if United States
4.2.3 Rest of World¶
This will return True is US or Canada return False. This will not be defined if either Canada or US is undefined.
- isC3GP.isOthC3GP()¶
returns boolean if rest of world
4.3 Examples¶
The highlights in this sections are views of code from the actual unit tests. In this fashion there is a strong assurance that the code worked for at the relevant software. On the assumption that geography is already installed on the site, these import statements will ensure that the code is loaded.
from cannuckfind import geolocation
from cannuckfind import C3
The demonstration the use of a function is shown in four steps:
1 testisCanC3GP = geolocation.isC3GP()
2 testisCanC3GP.loadrawGP("Toronto, Canada")
3 junkval = testisCanC3GP.isCanC3GP()
4 self.assertTrue(junkval == True )
First, a test object is created in line 30. Then a string is entered via the loadraw member function. The isCanC3SC() member function returns a boolean. In this example, a True value is obtained as Toronto is in Canada.
In this example, the object is reused but tested with Paris France. This returns a False, as would be expected.
testisCanC3GP.loadrawGP("Paris, France")
junkval = testisCanC3GP.isCanC3GP()
self.assertTrue(junkval == False )