|
@@ -9,6 +9,7 @@ class PpixBuilder:
|
|
|
self.collections = []
|
|
|
self.tags = {}
|
|
|
self.pubs = []
|
|
|
+ self.alternative_locations = []
|
|
|
|
|
|
self.word_tree = word_tree.WordBit()
|
|
|
|
|
@@ -51,10 +52,14 @@ class PpixBuilder:
|
|
|
self.words[word] = collection_index
|
|
|
|
|
|
|
|
|
+ def add_alternative_location(self, url):
|
|
|
+ self.alternative_locations.append(url)
|
|
|
+
|
|
|
+
|
|
|
def write_out(self, stream):
|
|
|
# Magic number
|
|
|
stream.write(b"PPIX\x00")
|
|
|
- start = 21
|
|
|
+ start = 35
|
|
|
|
|
|
publication_index_start = start
|
|
|
publication_index = self.serialise_publication_index(start)
|
|
@@ -68,10 +73,17 @@ class PpixBuilder:
|
|
|
tag_index = self.serialise_tags()
|
|
|
start += len(tag_index)
|
|
|
|
|
|
+ alternative_location_index_start = start
|
|
|
+ alternative_location_index = self.serialise_alternative_locations()
|
|
|
+ start += len(alternative_location_index)
|
|
|
+
|
|
|
stream.write(struct.pack("<IIII", publication_index_start, collection_index_start, tag_index_start, start))
|
|
|
+ stream.write(b"ECMDATA\x00")
|
|
|
+ stream.write(struct.pack("<HI", 1, alternative_location_index_start))
|
|
|
stream.write(publication_index)
|
|
|
stream.write(collection_index)
|
|
|
stream.write(tag_index)
|
|
|
+ stream.write(alternative_location_index)
|
|
|
|
|
|
self.serialise_word_tree(start, stream)
|
|
|
stream.flush()
|
|
@@ -113,6 +125,16 @@ class PpixBuilder:
|
|
|
|
|
|
return data
|
|
|
|
|
|
+ def serialise_alternative_locations(self):
|
|
|
+ data = struct.pack("<H", len(self.alternative_locations))
|
|
|
+
|
|
|
+ for location in self.alternative_locations:
|
|
|
+ encoded = location.encode("utf-8")
|
|
|
+ data += struct.pack("<H", len(encoded))
|
|
|
+ data += encoded
|
|
|
+
|
|
|
+ return data
|
|
|
+
|
|
|
def serialise_word_tree(self, start_position, stream):
|
|
|
words = sorted(((self.string_to_bool_array(k), v) for k, v in self.words.items()), key=lambda x: x[0][0])
|
|
|
root = word_tree.WordBit()
|