|
3 | 3 |
|
4 | 4 | @author: wf |
5 | 5 | ''' |
6 | | -from datasources.openresearch import OREventCorpus, OREventManager |
| 6 | +from corpus.lookup import CorpusLookup |
7 | 7 | from lodstorage.storageconfig import StorageConfig |
8 | | - |
9 | 8 | from ormigrate.toolbox import HelperFunctions as hf |
10 | 9 | from wikifile.wikiFileManager import WikiFileManager |
11 | 10 | from os import path |
12 | 11 | import os |
| 12 | + |
| 13 | + |
13 | 14 | class CorpusForTesting(object): |
14 | 15 | ''' |
15 | 16 | Simplify initializing an EventCorpus for tests (singleton) |
16 | 17 | ''' |
17 | | - |
18 | 18 | wikiId='orclone' |
19 | 19 |
|
20 | | - |
21 | 20 | @classmethod |
22 | 21 | def hasCache(cls): |
23 | 22 | ''' |
@@ -48,29 +47,70 @@ def getWikiFileManager(cls,wikiId=None,debug=False): |
48 | 47 | return wikiFileManager |
49 | 48 |
|
50 | 49 | @classmethod |
51 | | - def getEventCorpusFromWikiAPI(cls, wikiId=None, force=False, debug=False): |
| 50 | + def getEventDataSourceFromWikiAPI(cls, lookupId:str= "orclone", forceUpdate:bool=False, debug:bool=False): |
52 | 51 | ''' |
53 | 52 | get events with series by knitting / linking the entities together |
| 53 | +
|
| 54 | + Args: |
| 55 | + lookupId(str): ID of the EventDataSource that should be returned. |
| 56 | + forceUpdate(bool): True if the data should be fetched from the source instead of the cache |
| 57 | + debug(bool): If True display debug output |
| 58 | +
|
| 59 | + Returns: |
| 60 | + EventDataSource |
54 | 61 | ''' |
55 | | - wikiUser=cls.getWikiUser(wikiId) |
56 | | - config = cls.getStorageConfig() |
57 | | - eventCorpus=OREventCorpus(config,debug=debug) |
58 | | - eventCorpus.fromCache(wikiUser,force=force) |
59 | | - eventCorpus.wikiFileManager=cls.getWikiFileManager(wikiId, debug) |
60 | | - return eventCorpus |
| 62 | + eventDataSource=cls.getEventDataSource(lookupId=lookupId, forceUpdate=forceUpdate, debug=debug) |
| 63 | + return eventDataSource |
61 | 64 |
|
62 | 65 | @classmethod |
63 | | - def getEventCorpusFromWikiText(cls,wikiId=None,debug=False): |
| 66 | + def getEventDataSourceFromWikiText(cls, lookupId:str= "orclone-backup", forceUpdate:bool=False, debug=False): |
64 | 67 | """ |
65 | 68 | get events with series by knitting/linking entities from a WikiFileManager |
| 69 | +
|
| 70 | + Args: |
| 71 | + lookupId(str): ID of the EventDataSource that should be returned. |
| 72 | + forceUpdate(bool): True if the data should be fetched from the source instead of the cache |
| 73 | + debug(bool): If True display debug output |
| 74 | +
|
| 75 | + Returns: |
| 76 | + EventDataSource |
66 | 77 | """ |
67 | | - if wikiId is None: |
68 | | - wikiId=cls.wikiId |
69 | | - config=cls.getStorageConfig() |
70 | | - wikiFileManager=cls.getWikiFileManager(wikiId,debug) |
71 | | - eventCorpus=OREventCorpus(config,debug=debug) |
72 | | - eventCorpus.fromWikiFileManager(wikiFileManager) |
73 | | - return eventCorpus |
| 78 | + eventDataSource = cls.getEventDataSource(lookupId=lookupId, forceUpdate=forceUpdate, debug=debug) |
| 79 | + return eventDataSource |
| 80 | + |
| 81 | + @classmethod |
| 82 | + def getEventDataSource(cls, lookupId:str, forceUpdate:bool=False, debug:bool=False): |
| 83 | + """ |
| 84 | +
|
| 85 | + Args: |
| 86 | + lookupId(str): ID of the EventDataSource that should be returned. |
| 87 | + forceUpdate(bool): True if the data should be fetched from the source instead of the cache |
| 88 | + debug(bool): If True display debug output |
| 89 | +
|
| 90 | + Returns: |
| 91 | + EventDataSource |
| 92 | + """ |
| 93 | + lookup = CorpusLookup(lookupIds=[lookupId], configure=cls.patchEventSource, debug=debug) |
| 94 | + lookup.load(forceUpdate=forceUpdate) |
| 95 | + eventDataSource = lookup.getDataSource(lookupId) |
| 96 | + return eventDataSource |
| 97 | + |
| 98 | + @classmethod |
| 99 | + def patchEventSource(cls, lookup:CorpusLookup): |
| 100 | + ''' |
| 101 | + patches the EventManager and EventSeriesManager by adding wikiUser and WikiFileManager |
| 102 | + ''' |
| 103 | + wikiUser = cls.getWikiUser(cls.wikiId) |
| 104 | + wikiFileManager = cls.getWikiFileManager(cls.wikiId) |
| 105 | + for lookupId in ["orclone", "orclone-backup", "or", "or-backup"]: |
| 106 | + orDataSource = lookup.getDataSource(lookupId) |
| 107 | + if orDataSource is not None: |
| 108 | + if lookupId.endswith("-backup"): |
| 109 | + orDataSource.eventManager.wikiFileManager = wikiFileManager |
| 110 | + orDataSource.eventSeriesManager.wikiFileManager = wikiFileManager |
| 111 | + else: |
| 112 | + orDataSource.eventManager.wikiUser = wikiUser |
| 113 | + orDataSource.eventSeriesManager.wikiUser = wikiUser |
74 | 114 |
|
75 | 115 | @classmethod |
76 | 116 | def getStorageConfig(cls): |
|
0 commit comments