-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
save entity/page dump with zstd compression
- Loading branch information
Binh Vu
committed
Jan 21, 2024
1 parent
7944c79
commit 34cf045
Showing
8 changed files
with
168 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,49 @@ | ||
from __future__ import annotations | ||
|
||
import importlib | ||
from io import BytesIO | ||
from typing import Type | ||
|
||
import zstandard as zstd | ||
|
||
|
||
def split_tab_2(x: str) -> tuple[str, str]: | ||
k, v = x.split("\t") | ||
return (k, v) | ||
|
||
|
||
TYPE_ALIASES = {"typing.List": "list", "typing.Dict": "dict", "typing.Set": "set"} | ||
|
||
|
||
def get_import_path(type: Type) -> str: | ||
if type.__module__ == "builtins": | ||
return type.__qualname__ | ||
|
||
if hasattr(type, "__qualname__"): | ||
return type.__module__ + "." + type.__qualname__ | ||
|
||
# typically a class from the typing module | ||
if hasattr(type, "_name") and type._name is not None: | ||
path = type.__module__ + "." + type._name | ||
if path in TYPE_ALIASES: | ||
path = TYPE_ALIASES[path] | ||
elif hasattr(type, "__origin__") and hasattr(type.__origin__, "_name"): | ||
# found one case which is typing.Union | ||
path = type.__module__ + "." + type.__origin__._name | ||
else: | ||
raise NotImplementedError(type) | ||
|
||
return path | ||
|
||
|
||
def import_attr(attr_ident: str): | ||
lst = attr_ident.rsplit(".", 1) | ||
module, cls = lst | ||
module = importlib.import_module(module) | ||
return getattr(module, cls) | ||
|
||
|
||
def deser_zstd_records(dat: bytes): | ||
cctx = zstd.ZstdDecompressor() | ||
datobj = BytesIO(dat) | ||
return [x.decode() for x in cctx.stream_reader(datobj).readall().splitlines()] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[project] | ||
name = "kgdata" | ||
version = "6.3.1" | ||
version = "6.3.2" | ||
description = "Library to process dumps of knowledge graphs (Wikipedia, DBpedia, Wikidata)" | ||
readme = "README.md" | ||
authors = [{ name = "Binh Vu", email = "[email protected]" }] | ||
|
@@ -25,7 +25,7 @@ dependencies = [ | |
'redis >= 3.5.3, < 4.0.0', | ||
'numpy >= 1.22.3, < 2.0.0', | ||
'requests >= 2.28.0, < 3.0.0', | ||
'sem-desc >= 6.0.0, < 7.0.0', | ||
'sem-desc >= 6.7.2, < 7.0.0', | ||
'click >= 8.1.3, < 9.0.0', | ||
'parsimonious >= 0.8.1, < 0.9.0', | ||
'hugedict >= 2.12.5, < 3.0.0', | ||
|