3 Functions to use SpaCy¶
The class isC3SC is available to process string data for locational information. It is built on the SpaCy library.
3.1 Use of object¶
A number of functions were added to support the use of the SpaCy package. This class can be used to create the object.
- class geolocation.isC3SC¶
Object that uses SpaCy
An instance of this class is created with
- isC3SC.__init__()¶
Constructor Method
with each string containing a potential location, it can be loaded with this method.
- isC3SC.loadSCraw()¶
Loads record for further analysis
- Parameters
rawtext – A string of text of be analyzed
3.2 Boolean indicators for country¶
Now for the C3 case the locations will be Canadian, US and Rest of World. Note that the actual text to be analyszed only has to be loaded once by the loadraw member function above. In general these functions will respond with boolean functions. However, a spurious input may generate a different kind of response.
3.2.1 Canada¶
Once loadSCraw has loaded the text will return True if the location appears to be Canadian, or False otherwise.
- isC3SC.isCanC3SC()¶
See if raw text locates as Canada
- Returns
True if Canadian
3.2.2 United States¶
- isC3SC.isUSC3SC()¶
See if raw text locates as United States
- Returns
True if US
3.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.
- isC3SC.isOthC3SC()¶
See if raw text locates from rest of world
- Returns
True if rest of world
3.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 1. Then a string is entered via the loadSCraw 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 )