| @@ 102-112 (lines=11) @@ | ||
| 99 | f"invalid label type {lt}", backend_id=self.backend_id |
|
| 100 | ) |
|
| 101 | ||
| 102 | def _initialize_index(self) -> None: |
|
| 103 | if self._index is None: |
|
| 104 | path = os.path.join(self.datadir, self.INDEX_FILE) |
|
| 105 | if os.path.exists(path): |
|
| 106 | self._index = joblib.load(path) |
|
| 107 | self.debug(f"Loaded index from {path} with {len(self._index)} labels") |
|
| 108 | else: |
|
| 109 | self.info("Creating index") |
|
| 110 | self._index = self._create_index() |
|
| 111 | self._save_index(path) |
|
| 112 | self.info(f"Created index with {len(self._index)} labels") |
|
| 113 | ||
| 114 | def _save_index(self, path: str) -> None: |
|
| 115 | annif.util.atomic_save( |
|
| @@ 72-82 (lines=11) @@ | ||
| 69 | def initialize(self, parallel: bool = False) -> None: |
|
| 70 | self._initialize_index() |
|
| 71 | ||
| 72 | def _initialize_index(self) -> None: |
|
| 73 | if self._index is None: |
|
| 74 | path = os.path.join(self.datadir, self.INDEX_FILE) |
|
| 75 | if os.path.exists(path): |
|
| 76 | self._index = joblib.load(path) |
|
| 77 | self.debug(f"Loaded index from {path} with {len(self._index)} labels") |
|
| 78 | else: |
|
| 79 | self.info("Creating index") |
|
| 80 | self._index = self._create_index() |
|
| 81 | self._save_index(path) |
|
| 82 | self.info(f"Created index with {len(self._index)} labels") |
|
| 83 | ||
| 84 | def _save_index(self, path: str) -> None: |
|
| 85 | annif.util.atomic_save( |
|