flpq-data 6.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- flpq_data/__init__.py +24 -0
- flpq_data/config.py +16 -0
- flpq_data/dataset/__init__.py +4 -0
- flpq_data/dataset/cache.py +105 -0
- flpq_data/dataset/data.py +176 -0
- flpq_data/dataset/reachable_pairs.csv +156 -0
- flpq_data/dataset/reachable_pairs.py +129 -0
- flpq_data/dataset/registry.json +2229 -0
- flpq_data/dataset/registry.py +166 -0
- flpq_data/graphs/__init__.py +4 -0
- flpq_data/graphs/converters.py +125 -0
- flpq_data/graphs/generators/__init__.py +6 -0
- flpq_data/graphs/generators/fast_labeled_binomial_graph.py +90 -0
- flpq_data/graphs/generators/labeled_barabasi_albert_graph.py +86 -0
- flpq_data/graphs/generators/labeled_binomial_graph.py +81 -0
- flpq_data/graphs/generators/labeled_cycle_graph.py +53 -0
- flpq_data/graphs/generators/labeled_scale_free_graph.py +107 -0
- flpq_data/graphs/generators/labeled_two_cycles_graph.py +85 -0
- flpq_data/graphs/readwrite/__init__.py +4 -0
- flpq_data/graphs/readwrite/graph.py +41 -0
- flpq_data/graphs/readwrite/mtx.py +408 -0
- flpq_data/graphs/readwrite/rdf.py +253 -0
- flpq_data/graphs/readwrite/txt.py +280 -0
- flpq_data/graphs/utils/__init__.py +7 -0
- flpq_data/graphs/utils/add_reverse_edges.py +83 -0
- flpq_data/graphs/utils/change_edges.py +56 -0
- flpq_data/graphs/utils/edges_statistics.py +85 -0
- flpq_data/graphs/utils/filter_edges.py +50 -0
- flpq_data/graphs/utils/multiple_source_utils.py +268 -0
- flpq_data/graphs/utils/nodes_to_integers.py +49 -0
- flpq_data/graphs/utils/to_g_text.py +145 -0
- flpq_data/py.typed +0 -0
- flpq_data/queries/__init__.py +3 -0
- flpq_data/queries/cfpq/__init__.py +4 -0
- flpq_data/queries/cfpq/converters/__init__.py +2 -0
- flpq_data/queries/cfpq/converters/cfg.py +162 -0
- flpq_data/queries/cfpq/converters/cnf.py +135 -0
- flpq_data/queries/cfpq/generators/__init__.py +4 -0
- flpq_data/queries/cfpq/generators/c_alias_grammar.py +77 -0
- flpq_data/queries/cfpq/generators/dyck_grammar.py +75 -0
- flpq_data/queries/cfpq/generators/java_points_to_grammar.py +174 -0
- flpq_data/queries/cfpq/generators/nested_parentheses_grammar.py +69 -0
- flpq_data/queries/cfpq/readwrite/__init__.py +3 -0
- flpq_data/queries/cfpq/readwrite/cfg.py +167 -0
- flpq_data/queries/cfpq/readwrite/cnf.py +93 -0
- flpq_data/queries/cfpq/readwrite/cnf_template.py +464 -0
- flpq_data/queries/cfpq/utils/__init__.py +1 -0
- flpq_data/queries/cfpq/utils/change_terminals.py +178 -0
- flpq_data/queries/mcfpq/__init__.py +1 -0
- flpq_data/queries/mcfpq/readwrite/__init__.py +1 -0
- flpq_data/queries/mcfpq/readwrite/mcfg.py +357 -0
- flpq_data/queries/rpq/__init__.py +1 -0
- flpq_data/queries/rpq/readwrite/__init__.py +2 -0
- flpq_data/queries/rpq/readwrite/regex.py +151 -0
- flpq_data/queries/rpq/readwrite/rsa.py +396 -0
- flpq_data-6.0.0.dist-info/METADATA +142 -0
- flpq_data-6.0.0.dist-info/RECORD +60 -0
- flpq_data-6.0.0.dist-info/WHEEL +4 -0
- flpq_data-6.0.0.dist-info/licenses/LICENSE-DATA.txt +296 -0
- flpq_data-6.0.0.dist-info/licenses/LICENSE.txt +208 -0
flpq_data/__init__.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""
|
|
2
|
+
flpq_data
|
|
3
|
+
=========
|
|
4
|
+
|
|
5
|
+
flpq_data is a Python package for the creation, manipulation, and study of
|
|
6
|
+
the structure, dynamics, and functions of complex Graphs and formal-language
|
|
7
|
+
queries (regular, context-free, and multiple context-free) used for
|
|
8
|
+
experimental analysis of formal-language-constrained path querying algorithms
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import logging
|
|
12
|
+
|
|
13
|
+
from flpq_data.config import *
|
|
14
|
+
from flpq_data.dataset import *
|
|
15
|
+
from flpq_data.graphs import *
|
|
16
|
+
from flpq_data.queries import *
|
|
17
|
+
|
|
18
|
+
__version__ = VERSION
|
|
19
|
+
|
|
20
|
+
logging.basicConfig(
|
|
21
|
+
level=logging.INFO,
|
|
22
|
+
format="[%(asctime)s]>%(levelname)s>%(message)s",
|
|
23
|
+
datefmt="%Y-%m-%d %H:%M:%S",
|
|
24
|
+
)
|
flpq_data/config.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import pathlib
|
|
2
|
+
|
|
3
|
+
__all__ = [
|
|
4
|
+
"VERSION",
|
|
5
|
+
"DATASET_VERSION",
|
|
6
|
+
"ROOT",
|
|
7
|
+
]
|
|
8
|
+
|
|
9
|
+
VERSION = "6.0.0"
|
|
10
|
+
|
|
11
|
+
#: The dataset version served on object storage: the package major version
|
|
12
|
+
#: with zeroed minor and patch (a minor/patch release does not move the
|
|
13
|
+
#: dataset).
|
|
14
|
+
DATASET_VERSION = f"{VERSION[0]}.0.0"
|
|
15
|
+
|
|
16
|
+
ROOT = pathlib.Path(__file__).parent
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""Machine-global, version-preserving cache for downloaded dataset data."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import pathlib
|
|
5
|
+
import shutil
|
|
6
|
+
|
|
7
|
+
import platformdirs
|
|
8
|
+
|
|
9
|
+
from flpq_data.config import DATASET_VERSION
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"CACHE_ENV_VAR",
|
|
13
|
+
"cache_root",
|
|
14
|
+
"version_dir",
|
|
15
|
+
"cached_versions",
|
|
16
|
+
"clear_cache",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
#: Environment variable overriding the cache root.
|
|
20
|
+
CACHE_ENV_VAR = "FLPQ_DATA_CACHE"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def cache_root() -> pathlib.Path:
|
|
24
|
+
"""Return the effective cache root.
|
|
25
|
+
|
|
26
|
+
The ``FLPQ_DATA_CACHE`` environment variable wins when set to a
|
|
27
|
+
non-empty value; otherwise the OS default from
|
|
28
|
+
``platformdirs.user_cache_dir("flpq-data")`` (``~/.cache/flpq-data`` on
|
|
29
|
+
Linux, ``~/Library/Caches/flpq-data`` on macOS,
|
|
30
|
+
``%LOCALAPPDATA%\\flpq-data\\Cache`` on Windows).
|
|
31
|
+
|
|
32
|
+
Returns
|
|
33
|
+
-------
|
|
34
|
+
root : pathlib.Path
|
|
35
|
+
The cache root directory (not necessarily existing yet).
|
|
36
|
+
"""
|
|
37
|
+
env = os.environ.get(CACHE_ENV_VAR)
|
|
38
|
+
if env:
|
|
39
|
+
return pathlib.Path(env)
|
|
40
|
+
return pathlib.Path(platformdirs.user_cache_dir("flpq-data"))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def version_dir(version: str | None = None) -> pathlib.Path:
|
|
44
|
+
"""Return the cache directory of a dataset version.
|
|
45
|
+
|
|
46
|
+
Parameters
|
|
47
|
+
----------
|
|
48
|
+
version : str, optional
|
|
49
|
+
The dataset version; defaults to the current one (the package major
|
|
50
|
+
version with zeroed minor and patch).
|
|
51
|
+
|
|
52
|
+
Returns
|
|
53
|
+
-------
|
|
54
|
+
path : pathlib.Path
|
|
55
|
+
``<cache_root>/<version>`` (not necessarily existing yet).
|
|
56
|
+
"""
|
|
57
|
+
return cache_root() / (version or DATASET_VERSION)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def cached_versions() -> list[str]:
|
|
61
|
+
"""Return the dataset versions present in the cache.
|
|
62
|
+
|
|
63
|
+
Returns
|
|
64
|
+
-------
|
|
65
|
+
versions : list of str
|
|
66
|
+
The directory names under the cache root, sorted; empty when the
|
|
67
|
+
root does not exist.
|
|
68
|
+
"""
|
|
69
|
+
root = cache_root()
|
|
70
|
+
if not root.is_dir():
|
|
71
|
+
return []
|
|
72
|
+
return sorted(p.name for p in root.iterdir() if p.is_dir())
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def clear_cache(keep: str | None = None) -> list[pathlib.Path]:
|
|
76
|
+
"""Remove the cached dataset versions, optionally keeping one.
|
|
77
|
+
|
|
78
|
+
Every version directory under the cache root is removed except the one
|
|
79
|
+
named by ``keep``; ``keep=None`` removes all of them. Non-directory
|
|
80
|
+
entries under the root are left untouched.
|
|
81
|
+
|
|
82
|
+
Parameters
|
|
83
|
+
----------
|
|
84
|
+
keep : str, optional
|
|
85
|
+
The dataset version to keep (default ``None`` — remove everything).
|
|
86
|
+
|
|
87
|
+
Examples
|
|
88
|
+
--------
|
|
89
|
+
>>> from flpq_data import *
|
|
90
|
+
>>> clear_cache() # doctest: +SKIP
|
|
91
|
+
[]
|
|
92
|
+
|
|
93
|
+
Returns
|
|
94
|
+
-------
|
|
95
|
+
removed : list of Path
|
|
96
|
+
The removed version directories, in sorted order; empty when the
|
|
97
|
+
cache root does not exist or nothing was removed.
|
|
98
|
+
"""
|
|
99
|
+
root = cache_root()
|
|
100
|
+
if not root.is_dir():
|
|
101
|
+
return []
|
|
102
|
+
removed = [p for p in sorted(root.iterdir()) if p.is_dir() and p.name != keep]
|
|
103
|
+
for path in removed:
|
|
104
|
+
shutil.rmtree(path)
|
|
105
|
+
return removed
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"""Download graph data from dataset."""
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import logging
|
|
5
|
+
import os
|
|
6
|
+
import pathlib
|
|
7
|
+
import shutil
|
|
8
|
+
import tempfile
|
|
9
|
+
import warnings
|
|
10
|
+
|
|
11
|
+
import requests
|
|
12
|
+
|
|
13
|
+
from flpq_data.config import DATASET_VERSION
|
|
14
|
+
from flpq_data.dataset.cache import version_dir
|
|
15
|
+
from flpq_data.dataset.registry import GraphInfo, graph_info
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"DATASET_KEY_PREFIX",
|
|
19
|
+
"DATASET_URL",
|
|
20
|
+
"graph_dir",
|
|
21
|
+
"download_graph",
|
|
22
|
+
"download",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
DATASET_KEY_PREFIX = f"{DATASET_VERSION}/graph"
|
|
26
|
+
DATASET_URL = f"https://cfpq-data.storage.yandexcloud.net/{DATASET_KEY_PREFIX}/"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _sha256(path: pathlib.Path) -> str:
|
|
30
|
+
"""Returns the streaming sha256 hex digest of a file."""
|
|
31
|
+
hasher = hashlib.sha256()
|
|
32
|
+
with path.open("rb") as f:
|
|
33
|
+
for chunk in iter(lambda: f.read(1 << 20), b""):
|
|
34
|
+
hasher.update(chunk)
|
|
35
|
+
return hasher.hexdigest()
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _install(name: str, info: GraphInfo, dest: pathlib.Path) -> None:
|
|
39
|
+
"""Download, verify, and install the archive of ``name`` into ``dest``.
|
|
40
|
+
|
|
41
|
+
The download is streamed to a temp file with a running sha256; only a
|
|
42
|
+
verified archive is unpacked and moved into place, so any failure leaves
|
|
43
|
+
``dest`` untouched and removes the temp files.
|
|
44
|
+
"""
|
|
45
|
+
parent = dest.parent
|
|
46
|
+
parent.mkdir(parents=True, exist_ok=True)
|
|
47
|
+
fd, tmp_archive_str = tempfile.mkstemp(dir=parent, suffix=".tar.gz")
|
|
48
|
+
os.close(fd)
|
|
49
|
+
tmp_archive = pathlib.Path(tmp_archive_str)
|
|
50
|
+
tmp_extract: pathlib.Path | None = None
|
|
51
|
+
try:
|
|
52
|
+
logging.info(f"Downloading {DATASET_URL}{name}.tar.gz")
|
|
53
|
+
with requests.get(url=DATASET_URL + f"{name}.tar.gz", stream=True) as r:
|
|
54
|
+
r.raise_for_status()
|
|
55
|
+
hasher = hashlib.sha256()
|
|
56
|
+
with tmp_archive.open("wb") as out:
|
|
57
|
+
for chunk in iter(lambda: r.raw.read(1 << 20), b""):
|
|
58
|
+
hasher.update(chunk)
|
|
59
|
+
out.write(chunk)
|
|
60
|
+
digest = hasher.hexdigest()
|
|
61
|
+
if digest != info.sha256:
|
|
62
|
+
raise ValueError(
|
|
63
|
+
f"sha256 mismatch for {name}: expected {info.sha256}, got {digest}"
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
tmp_extract = pathlib.Path(tempfile.mkdtemp(dir=parent))
|
|
67
|
+
shutil.unpack_archive(tmp_archive, tmp_extract)
|
|
68
|
+
|
|
69
|
+
entries = list(tmp_extract.iterdir())
|
|
70
|
+
if len(entries) != 1 or not entries[0].is_dir():
|
|
71
|
+
raise ValueError(
|
|
72
|
+
f"Archive for {name=} must contain a single "
|
|
73
|
+
f"top-level directory, found {entries=}"
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
if dest.exists():
|
|
77
|
+
shutil.rmtree(dest)
|
|
78
|
+
shutil.move(str(entries[0]), str(dest))
|
|
79
|
+
shutil.move(str(tmp_archive), str(dest / f"{name}.tar.gz"))
|
|
80
|
+
(dest / f"{name}.tar.gz.sha256").write_text(digest + "\n")
|
|
81
|
+
|
|
82
|
+
logging.info(f"Installed graph {name=} to directory {dest=}")
|
|
83
|
+
finally:
|
|
84
|
+
if tmp_archive.exists():
|
|
85
|
+
tmp_archive.unlink()
|
|
86
|
+
if tmp_extract is not None and tmp_extract.exists():
|
|
87
|
+
shutil.rmtree(tmp_extract, ignore_errors=True)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def graph_dir(name: str, verify: bool = False) -> pathlib.Path:
|
|
91
|
+
"""Return the local directory of a graph, downloading it on a cache miss.
|
|
92
|
+
|
|
93
|
+
The data lives in the machine-global cache (see :func:`cache_root`),
|
|
94
|
+
mirroring the dataset layout::
|
|
95
|
+
|
|
96
|
+
<root>/<version>/graph/<name>/<name>.tar.gz plus the unpacked
|
|
97
|
+
contents in the same folder
|
|
98
|
+
|
|
99
|
+
A cache hit — the folder and archive are present and the digest matches
|
|
100
|
+
the registry — returns the path with zero network. The digest is read
|
|
101
|
+
from the ``<name>.tar.gz.sha256`` sidecar written at install;
|
|
102
|
+
``verify=True`` re-hashes the archive instead of trusting the sidecar.
|
|
103
|
+
On a miss the archive is downloaded, its sha256 is verified against the
|
|
104
|
+
registry while streaming, it is unpacked (a single top-level directory
|
|
105
|
+
is required), and the result is moved into the cache; any failure leaves
|
|
106
|
+
the cache untouched.
|
|
107
|
+
|
|
108
|
+
Parameters
|
|
109
|
+
----------
|
|
110
|
+
name : str
|
|
111
|
+
The name of the graph from the dataset.
|
|
112
|
+
verify : bool, optional
|
|
113
|
+
Re-hash the cached archive against the registry instead of trusting
|
|
114
|
+
the sidecar digest (default ``False``).
|
|
115
|
+
|
|
116
|
+
Examples
|
|
117
|
+
--------
|
|
118
|
+
>>> from flpq_data import *
|
|
119
|
+
>>> path = graph_dir("generations")
|
|
120
|
+
>>> path.name
|
|
121
|
+
'generations'
|
|
122
|
+
|
|
123
|
+
Returns
|
|
124
|
+
-------
|
|
125
|
+
path : Path
|
|
126
|
+
Path to the directory with the graph data.
|
|
127
|
+
|
|
128
|
+
Raises
|
|
129
|
+
------
|
|
130
|
+
FileNotFoundError
|
|
131
|
+
If no graph with this name exists in the dataset.
|
|
132
|
+
"""
|
|
133
|
+
info = graph_info(name)
|
|
134
|
+
dest = version_dir() / "graph" / name
|
|
135
|
+
archive = dest / f"{name}.tar.gz"
|
|
136
|
+
sidecar = archive.with_name(archive.name + ".sha256")
|
|
137
|
+
|
|
138
|
+
if dest.is_dir() and archive.is_file():
|
|
139
|
+
if verify:
|
|
140
|
+
digest = _sha256(archive)
|
|
141
|
+
else:
|
|
142
|
+
digest = sidecar.read_text().strip() if sidecar.is_file() else None
|
|
143
|
+
if digest == info.sha256:
|
|
144
|
+
logging.info(f"Cache hit for graph {name=}")
|
|
145
|
+
return dest
|
|
146
|
+
|
|
147
|
+
_install(name, info, dest)
|
|
148
|
+
return dest
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def download_graph(name: str) -> pathlib.Path:
|
|
152
|
+
"""Deprecated alias of :func:`graph_dir`.
|
|
153
|
+
|
|
154
|
+
.. deprecated:: 6.0.0
|
|
155
|
+
Use :func:`graph_dir` instead.
|
|
156
|
+
"""
|
|
157
|
+
warnings.warn(
|
|
158
|
+
"download_graph() is deprecated, use graph_dir() instead",
|
|
159
|
+
DeprecationWarning,
|
|
160
|
+
stacklevel=2,
|
|
161
|
+
)
|
|
162
|
+
return graph_dir(name)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def download(name: str) -> pathlib.Path:
|
|
166
|
+
"""Deprecated alias of :func:`graph_dir`.
|
|
167
|
+
|
|
168
|
+
.. deprecated:: 6.0.0
|
|
169
|
+
Use :func:`graph_dir` instead.
|
|
170
|
+
"""
|
|
171
|
+
warnings.warn(
|
|
172
|
+
"download() is deprecated, use graph_dir() instead",
|
|
173
|
+
DeprecationWarning,
|
|
174
|
+
stacklevel=2,
|
|
175
|
+
)
|
|
176
|
+
return graph_dir(name)
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
graph,grammar,category,query_class,num_reachable_pairs
|
|
2
|
+
airflow,prov_derivation.cnf,data_provenance,cfpq,91350
|
|
3
|
+
apache,c_alias.cnf,c_alias_analysis,cfpq,92806768
|
|
4
|
+
arch,c_alias.cnf,c_alias_analysis,cfpq,5339563
|
|
5
|
+
atom,nested_parentheses_subClassOf.cnf,rdf,cfpq,2
|
|
6
|
+
atom,nested_parentheses_subClassOf_type.cnf,rdf,cfpq,6
|
|
7
|
+
atom,nested_parentheses_type.cnf,rdf,cfpq,4
|
|
8
|
+
avrora,java_points_to.cnf,java_points_to,cfpq,21532
|
|
9
|
+
batik,java_points_to.cnf,java_points_to,cfpq,45968
|
|
10
|
+
biomedical,nested_parentheses_subClassOf.cnf,rdf,cfpq,43
|
|
11
|
+
biomedical,nested_parentheses_subClassOf_type.cnf,rdf,cfpq,47
|
|
12
|
+
biomedical,nested_parentheses_type.cnf,rdf,cfpq,4
|
|
13
|
+
block,c_alias.cnf,c_alias_analysis,cfpq,5351409
|
|
14
|
+
bzip,c_alias.cnf,c_alias_analysis,cfpq,315
|
|
15
|
+
cactus,aa.cnf,context_sensitive_data_flow,cfpq,47806209
|
|
16
|
+
cactus_field_sensitive_alias,vf.cnf,field_sensitive_alias,cfpq,37625324
|
|
17
|
+
celery,prov_derivation.cnf,data_provenance,cfpq,25306
|
|
18
|
+
click,prov_derivation.cnf,data_provenance,cfpq,2710
|
|
19
|
+
commons_io,java_points_to.cnf,java_points_to,cfpq,24020
|
|
20
|
+
commons_lang3,java_points_to.cnf,java_points_to,cfpq,27553
|
|
21
|
+
core,nested_parentheses_subClassOf.cnf,rdf,cfpq,143
|
|
22
|
+
core,nested_parentheses_subClassOf_type.cnf,rdf,cfpq,204
|
|
23
|
+
core,nested_parentheses_type.cnf,rdf,cfpq,61
|
|
24
|
+
crypto,c_alias.cnf,c_alias_analysis,cfpq,5428237
|
|
25
|
+
django,prov_derivation.cnf,data_provenance,cfpq,615946
|
|
26
|
+
drivers,c_alias.cnf,c_alias_analysis,cfpq,18825025
|
|
27
|
+
eclass,nested_parentheses_subClassOf.cnf,rdf,cfpq,90988
|
|
28
|
+
eclass,nested_parentheses_subClassOf_type.cnf,rdf,cfpq,90994
|
|
29
|
+
eclass,nested_parentheses_type.cnf,rdf,cfpq,6
|
|
30
|
+
eclipse,java_points_to.cnf,java_points_to,cfpq,21830
|
|
31
|
+
enzyme,nested_parentheses_broaderTransitive.cnf,rdf,cfpq,14267542
|
|
32
|
+
enzyme,nested_parentheses_subClassOf.cnf,rdf,cfpq,394
|
|
33
|
+
enzyme,nested_parentheses_subClassOf_type.cnf,rdf,cfpq,396
|
|
34
|
+
enzyme,nested_parentheses_type.cnf,rdf,cfpq,3
|
|
35
|
+
fastapi,prov_derivation.cnf,data_provenance,cfpq,8814
|
|
36
|
+
flask,prov_derivation.cnf,data_provenance,cfpq,8062
|
|
37
|
+
foaf,nested_parentheses_subClassOf.cnf,rdf,cfpq,7
|
|
38
|
+
foaf,nested_parentheses_subClassOf_type.cnf,rdf,cfpq,36
|
|
39
|
+
foaf,nested_parentheses_type.cnf,rdf,cfpq,29
|
|
40
|
+
fop,java_points_to.cnf,java_points_to,cfpq,76615
|
|
41
|
+
fs,c_alias.cnf,c_alias_analysis,cfpq,9646475
|
|
42
|
+
funding,nested_parentheses_subClassOf.cnf,rdf,cfpq,27
|
|
43
|
+
funding,nested_parentheses_subClassOf_type.cnf,rdf,cfpq,58
|
|
44
|
+
funding,nested_parentheses_type.cnf,rdf,cfpq,31
|
|
45
|
+
generations,nested_parentheses_subClassOf.cnf,rdf,cfpq,0
|
|
46
|
+
generations,nested_parentheses_subClassOf_type.cnf,rdf,cfpq,12
|
|
47
|
+
generations,nested_parentheses_type.cnf,rdf,cfpq,12
|
|
48
|
+
geospecies,nested_parentheses_broaderTransitive.cnf,rdf,cfpq,226669749
|
|
49
|
+
geospecies,nested_parentheses_subClassOf.cnf,rdf,cfpq,0
|
|
50
|
+
geospecies,nested_parentheses_subClassOf_type.cnf,rdf,cfpq,85
|
|
51
|
+
geospecies,nested_parentheses_type.cnf,rdf,cfpq,85
|
|
52
|
+
go,nested_parentheses_subClassOf.cnf,rdf,cfpq,640305
|
|
53
|
+
go,nested_parentheses_subClassOf_type.cnf,rdf,cfpq,640316
|
|
54
|
+
go,nested_parentheses_type.cnf,rdf,cfpq,9
|
|
55
|
+
go_hierarchy,nested_parentheses_subClassOf.cnf,rdf,cfpq,588976
|
|
56
|
+
go_hierarchy,nested_parentheses_subClassOf_type.cnf,rdf,cfpq,588976
|
|
57
|
+
go_hierarchy,nested_parentheses_type.cnf,rdf,cfpq,0
|
|
58
|
+
gson,java_points_to.cnf,java_points_to,cfpq,56325
|
|
59
|
+
guava,java_points_to.cnf,java_points_to,cfpq,26384496
|
|
60
|
+
gzip,c_alias.cnf,c_alias_analysis,cfpq,1458
|
|
61
|
+
h2,java_points_to.cnf,java_points_to,cfpq,92038
|
|
62
|
+
httpx,prov_derivation.cnf,data_provenance,cfpq,4408
|
|
63
|
+
imagick,aa.cnf,context_sensitive_data_flow,cfpq,12687034
|
|
64
|
+
imagick_field_sensitive_alias,vf.cnf,field_sensitive_alias,cfpq,369956094
|
|
65
|
+
init,c_alias.cnf,c_alias_analysis,cfpq,3783769
|
|
66
|
+
ipc,c_alias.cnf,c_alias_analysis,cfpq,5249389
|
|
67
|
+
itsdangerous,prov_derivation.cnf,data_provenance,cfpq,2912
|
|
68
|
+
jackson,java_points_to.cnf,java_points_to,cfpq,3108775
|
|
69
|
+
jiaozi,name_resolution.cnf,name_resolution,cfpq,14435
|
|
70
|
+
jinja,prov_derivation.cnf,data_provenance,cfpq,7436
|
|
71
|
+
jsonpath,name_resolution.cnf,name_resolution,cfpq,59764
|
|
72
|
+
junit5,java_points_to.cnf,java_points_to,cfpq,129598
|
|
73
|
+
jython,java_points_to.cnf,java_points_to,cfpq,561720
|
|
74
|
+
kernel,c_alias.cnf,c_alias_analysis,cfpq,16747731
|
|
75
|
+
leela,aa.cnf,context_sensitive_data_flow,cfpq,662466
|
|
76
|
+
leela_field_sensitive_alias,vf.cnf,field_sensitive_alias,cfpq,3968276
|
|
77
|
+
lib,c_alias.cnf,c_alias_analysis,cfpq,5276303
|
|
78
|
+
libgdx,name_resolution.cnf,name_resolution,cfpq,
|
|
79
|
+
ls,c_alias.cnf,c_alias_analysis,cfpq,854
|
|
80
|
+
luindex,java_points_to.cnf,java_points_to,cfpq,9677
|
|
81
|
+
lusearch,java_points_to.cnf,java_points_to,cfpq,9242
|
|
82
|
+
mm,c_alias.cnf,c_alias_analysis,cfpq,3990305
|
|
83
|
+
mockito,java_points_to.cnf,java_points_to,cfpq,16169
|
|
84
|
+
nab,aa.cnf,context_sensitive_data_flow,cfpq,739646
|
|
85
|
+
nab_field_sensitive_alias,vf.cnf,field_sensitive_alias,cfpq,262566
|
|
86
|
+
net,c_alias.cnf,c_alias_analysis,cfpq,8833403
|
|
87
|
+
omnetpp,aa.cnf,context_sensitive_data_flow,cfpq,8424500
|
|
88
|
+
omnetpp_field_sensitive_alias,vf.cnf,field_sensitive_alias,cfpq,158255766
|
|
89
|
+
pandas,prov_derivation.cnf,data_provenance,cfpq,154646
|
|
90
|
+
parest,aa.cnf,context_sensitive_data_flow,cfpq,1342540
|
|
91
|
+
parest_field_sensitive_alias,vf.cnf,field_sensitive_alias,cfpq,49415038
|
|
92
|
+
pathways,nested_parentheses_subClassOf.cnf,rdf,cfpq,883
|
|
93
|
+
pathways,nested_parentheses_subClassOf_type.cnf,rdf,cfpq,884
|
|
94
|
+
pathways,nested_parentheses_type.cnf,rdf,cfpq,2
|
|
95
|
+
people,nested_parentheses_subClassOf.cnf,rdf,cfpq,24
|
|
96
|
+
people,nested_parentheses_subClassOf_type.cnf,rdf,cfpq,51
|
|
97
|
+
people,nested_parentheses_type.cnf,rdf,cfpq,29
|
|
98
|
+
perlbench,aa.cnf,context_sensitive_data_flow,cfpq,297504186
|
|
99
|
+
perlbench_field_sensitive_alias,vf.cnf,field_sensitive_alias,cfpq,851737865
|
|
100
|
+
pizza,nested_parentheses_subClassOf.cnf,rdf,cfpq,1334
|
|
101
|
+
pizza,nested_parentheses_subClassOf_type.cnf,rdf,cfpq,1356
|
|
102
|
+
pizza,nested_parentheses_type.cnf,rdf,cfpq,20
|
|
103
|
+
pluggy,prov_derivation.cnf,data_provenance,cfpq,880
|
|
104
|
+
pmd,java_points_to.cnf,java_points_to,cfpq,60518
|
|
105
|
+
postgre,c_alias.cnf,c_alias_analysis,cfpq,90661446
|
|
106
|
+
povray,aa.cnf,context_sensitive_data_flow,cfpq,34599413
|
|
107
|
+
povray_field_sensitive_alias,vf.cnf,field_sensitive_alias,cfpq,27219043
|
|
108
|
+
pr,c_alias.cnf,c_alias_analysis,cfpq,385
|
|
109
|
+
requests,prov_derivation.cnf,data_provenance,cfpq,2524
|
|
110
|
+
sampleproject,prov_derivation.cnf,data_provenance,cfpq,342
|
|
111
|
+
scikit-learn,prov_derivation.cnf,data_provenance,cfpq,217728
|
|
112
|
+
security,c_alias.cnf,c_alias_analysis,cfpq,5593387
|
|
113
|
+
shattered_pixel_dungeon,name_resolution.cnf,name_resolution,cfpq,971998
|
|
114
|
+
skos,nested_parentheses_subClassOf.cnf,rdf,cfpq,1
|
|
115
|
+
skos,nested_parentheses_subClassOf_type.cnf,rdf,cfpq,30
|
|
116
|
+
skos,nested_parentheses_type.cnf,rdf,cfpq,29
|
|
117
|
+
sound,c_alias.cnf,c_alias_analysis,cfpq,6085269
|
|
118
|
+
sphinx,prov_derivation.cnf,data_provenance,cfpq,304084
|
|
119
|
+
sunflow,java_points_to.cnf,java_points_to,cfpq,16354
|
|
120
|
+
superset,prov_derivation.cnf,data_provenance,cfpq,97460
|
|
121
|
+
taxonomy,nested_parentheses_subClassOf.cnf,rdf,cfpq,151703
|
|
122
|
+
taxonomy,nested_parentheses_subClassOf_type.cnf,rdf,cfpq,151706
|
|
123
|
+
taxonomy,nested_parentheses_type.cnf,rdf,cfpq,4
|
|
124
|
+
taxonomy_hierarchy,nested_parentheses_subClassOf.cnf,rdf,cfpq,5351657
|
|
125
|
+
taxonomy_hierarchy,nested_parentheses_subClassOf_type.cnf,rdf,cfpq,5351657
|
|
126
|
+
taxonomy_hierarchy,nested_parentheses_type.cnf,rdf,cfpq,0
|
|
127
|
+
tomcat,java_points_to.cnf,java_points_to,cfpq,82424
|
|
128
|
+
tradebeans,java_points_to.cnf,java_points_to,cfpq,696316
|
|
129
|
+
tradesoap,java_points_to.cnf,java_points_to,cfpq,698567
|
|
130
|
+
travel,nested_parentheses_subClassOf.cnf,rdf,cfpq,33
|
|
131
|
+
travel,nested_parentheses_subClassOf_type.cnf,rdf,cfpq,52
|
|
132
|
+
travel,nested_parentheses_type.cnf,rdf,cfpq,19
|
|
133
|
+
unigraph_1,unigraph_1.cnf,biological_uniprot,cfpq,376578
|
|
134
|
+
unigraph_10,unigraph_10.cnf,biological_uniprot,cfpq,
|
|
135
|
+
unigraph_2,unigraph_2.cnf,biological_uniprot,cfpq,39888347
|
|
136
|
+
unigraph_3,unigraph_3.cnf,biological_uniprot,cfpq,52471840
|
|
137
|
+
unigraph_4,unigraph_4.cnf,biological_uniprot,cfpq,808091802
|
|
138
|
+
unigraph_5,unigraph_5.cnf,biological_uniprot,cfpq,2303590109
|
|
139
|
+
unigraph_6,unigraph_6.cnf,biological_uniprot,cfpq,1722963921
|
|
140
|
+
unigraph_7,unigraph_7.cnf,biological_uniprot,cfpq,2320964134
|
|
141
|
+
unigraph_8,unigraph_8.cnf,biological_uniprot,cfpq,
|
|
142
|
+
unigraph_9,unigraph_9.cnf,biological_uniprot,cfpq,
|
|
143
|
+
univ,nested_parentheses_subClassOf.cnf,rdf,cfpq,17
|
|
144
|
+
univ,nested_parentheses_subClassOf_type.cnf,rdf,cfpq,25
|
|
145
|
+
univ,nested_parentheses_type.cnf,rdf,cfpq,6
|
|
146
|
+
wc,c_alias.cnf,c_alias_analysis,cfpq,156
|
|
147
|
+
wikipedia-provenance,prov_derivation.cnf,data_provenance,cfpq,1732
|
|
148
|
+
wine,nested_parentheses_subClassOf.cnf,rdf,cfpq,499
|
|
149
|
+
wine,nested_parentheses_subClassOf_type.cnf,rdf,cfpq,565
|
|
150
|
+
wine,nested_parentheses_type.cnf,rdf,cfpq,65
|
|
151
|
+
x264,aa.cnf,context_sensitive_data_flow,cfpq,20259480
|
|
152
|
+
x264_field_sensitive_alias,vf.cnf,field_sensitive_alias,cfpq,5246565
|
|
153
|
+
xalan,java_points_to.cnf,java_points_to,cfpq,52382
|
|
154
|
+
xz,aa.cnf,context_sensitive_data_flow,cfpq,358834
|
|
155
|
+
xz_field_sensitive_alias,vf.cnf,field_sensitive_alias,cfpq,205164
|
|
156
|
+
zulip,prov_derivation.cnf,data_provenance,cfpq,209908
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"""Reference reachable-pair counts for graph x grammar pairs."""
|
|
2
|
+
|
|
3
|
+
import csv
|
|
4
|
+
import logging
|
|
5
|
+
import pathlib
|
|
6
|
+
import shutil
|
|
7
|
+
from typing import Optional
|
|
8
|
+
|
|
9
|
+
import requests
|
|
10
|
+
|
|
11
|
+
from flpq_data.config import DATASET_VERSION
|
|
12
|
+
from flpq_data.dataset.cache import version_dir
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"REACHABLE_PAIRS_CSV",
|
|
16
|
+
"REACHABLE_PAIRS_KEY_PREFIX",
|
|
17
|
+
"REACHABLE_PAIRS_URL",
|
|
18
|
+
"download_reachable_pairs",
|
|
19
|
+
"reachable_pairs",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
REACHABLE_PAIRS_FILENAME = "reachable_pairs.csv"
|
|
23
|
+
|
|
24
|
+
#: Version prefix the table is published under on the dataset object storage.
|
|
25
|
+
#: Derived from :data:`flpq_data.config.DATASET_VERSION`, so the URL follows
|
|
26
|
+
#: the package version.
|
|
27
|
+
REACHABLE_PAIRS_KEY_PREFIX: str = DATASET_VERSION
|
|
28
|
+
|
|
29
|
+
#: Public URL of the versioned reachable-pairs CSV (see
|
|
30
|
+
#: :func:`download_reachable_pairs`).
|
|
31
|
+
REACHABLE_PAIRS_URL: str = (
|
|
32
|
+
f"https://cfpq-data.storage.yandexcloud.net/"
|
|
33
|
+
f"{REACHABLE_PAIRS_KEY_PREFIX}/{REACHABLE_PAIRS_FILENAME}"
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
#: Path to the reference CSV shipped with the package; always available
|
|
37
|
+
#: offline. :func:`download_reachable_pairs` fetches the versioned copy from
|
|
38
|
+
#: the dataset storage instead, and :func:`reachable_pairs` prefers it when
|
|
39
|
+
#: present.
|
|
40
|
+
REACHABLE_PAIRS_CSV: pathlib.Path = (
|
|
41
|
+
pathlib.Path(__file__).parent / REACHABLE_PAIRS_FILENAME
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def download_reachable_pairs() -> pathlib.Path:
|
|
46
|
+
"""Download the versioned reachable-pairs CSV from the dataset storage.
|
|
47
|
+
|
|
48
|
+
The table is also shipped with the package (``REACHABLE_PAIRS_CSV``);
|
|
49
|
+
this fetches the copy published under the current version prefix
|
|
50
|
+
(``REACHABLE_PAIRS_URL``) into the machine-global cache
|
|
51
|
+
(``version_dir() / "reachable_pairs.csv"``), so an updated table can be
|
|
52
|
+
consumed without reinstalling. Once downloaded, :func:`reachable_pairs`
|
|
53
|
+
reads it instead of the bundled copy.
|
|
54
|
+
|
|
55
|
+
Returns
|
|
56
|
+
-------
|
|
57
|
+
path : pathlib.Path
|
|
58
|
+
Path to the downloaded CSV.
|
|
59
|
+
|
|
60
|
+
Raises
|
|
61
|
+
------
|
|
62
|
+
requests.HTTPError
|
|
63
|
+
If the table is not available at ``REACHABLE_PAIRS_URL``.
|
|
64
|
+
"""
|
|
65
|
+
destination = version_dir() / REACHABLE_PAIRS_FILENAME
|
|
66
|
+
destination.parent.mkdir(exist_ok=True, parents=True)
|
|
67
|
+
logging.info(f"Downloading reachable pairs CSV from {REACHABLE_PAIRS_URL}")
|
|
68
|
+
with requests.get(url=REACHABLE_PAIRS_URL, stream=True) as response:
|
|
69
|
+
response.raise_for_status()
|
|
70
|
+
with open(destination, "wb") as file:
|
|
71
|
+
shutil.copyfileobj(response.raw, file)
|
|
72
|
+
logging.info(f"Downloaded reachable pairs CSV to {destination}")
|
|
73
|
+
return destination
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _csv_path() -> pathlib.Path:
|
|
77
|
+
"""Returns the CSV to read: the per-version cache copy if present, else bundled."""
|
|
78
|
+
cached = version_dir() / REACHABLE_PAIRS_FILENAME
|
|
79
|
+
return cached if cached.exists() else REACHABLE_PAIRS_CSV
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def reachable_pairs(
|
|
83
|
+
graph: Optional[str] = None,
|
|
84
|
+
grammar: Optional[str] = None,
|
|
85
|
+
category: Optional[str] = None,
|
|
86
|
+
query_class: Optional[str] = None,
|
|
87
|
+
) -> list[dict]:
|
|
88
|
+
"""Return reference reachable-pair counts.
|
|
89
|
+
|
|
90
|
+
Each row is a dict with keys ``graph``, ``grammar``, ``category``,
|
|
91
|
+
``query_class``, and ``num_reachable_pairs`` (int or None when not yet
|
|
92
|
+
available).
|
|
93
|
+
|
|
94
|
+
Parameters
|
|
95
|
+
----------
|
|
96
|
+
graph:
|
|
97
|
+
Filter by graph name (exact match).
|
|
98
|
+
grammar:
|
|
99
|
+
Filter by grammar file name (exact match, e.g. ``"c_alias.cnf"``).
|
|
100
|
+
category:
|
|
101
|
+
Filter by graph category (exact match, e.g. ``"rdf"``); the
|
|
102
|
+
categories are the sections of the Graphs catalog on the site.
|
|
103
|
+
query_class:
|
|
104
|
+
Filter by query class (exact match, one of ``"cfpq"``, ``"rpq"``,
|
|
105
|
+
``"mcfpq"`` — the names of the ``queries/<class>/`` directories in
|
|
106
|
+
the graph archives).
|
|
107
|
+
"""
|
|
108
|
+
rows: list[dict] = []
|
|
109
|
+
with _csv_path().open(newline="") as f:
|
|
110
|
+
for row in csv.DictReader(f):
|
|
111
|
+
if graph is not None and row["graph"] != graph:
|
|
112
|
+
continue
|
|
113
|
+
if grammar is not None and row["grammar"] != grammar:
|
|
114
|
+
continue
|
|
115
|
+
if category is not None and row["category"] != category:
|
|
116
|
+
continue
|
|
117
|
+
if query_class is not None and row["query_class"] != query_class:
|
|
118
|
+
continue
|
|
119
|
+
val = row["num_reachable_pairs"]
|
|
120
|
+
rows.append(
|
|
121
|
+
{
|
|
122
|
+
"graph": row["graph"],
|
|
123
|
+
"grammar": row["grammar"],
|
|
124
|
+
"category": row["category"],
|
|
125
|
+
"query_class": row["query_class"],
|
|
126
|
+
"num_reachable_pairs": int(val) if val else None,
|
|
127
|
+
}
|
|
128
|
+
)
|
|
129
|
+
return rows
|