Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
"""Build RDF with rdflib and serialize in turtle format.""" | |
import rdflib | |
from rdflib.namespace import DCTERMS, RDF, RDFS, SKOS | |
GOLD = rdflib.Namespace('http://purl.org/linguistics/gold/') | |
LANGUOID = rdflib.Namespace('http://glottolog.org/resource/languoid/id/') | |
VOID = rdflib.Namespace('http://rdfs.org/ns/void#') |
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
"""Benchmark PostgreSQL array vs. join performance. | |
Replicate http://shon.github.io/2015/12/21/postgres_array_performance.html | |
with proper join table indexes (uniqueness constraints) using SQLAlchemy. | |
$ python -i bench_pg_array.py | |
>>> setup() | |
$ python -m timeit -s "import bench_pg_array" "bench_pg_array.test_join()" | |
500 loops, best of 5: 445 usec per loop |
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
"""Dump basic https://glottolog.org languoid info to CSV file.""" | |
import pandas as pd | |
ENGINE = 'postgresql://postgres@/glottolog3' | |
QUERY = ''' | |
SELECT | |
l.id AS glottocode, | |
l.name, |
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
"""Generate concepts by trying all combinations with NumPy.""" | |
from collections.abc import Iterator, Sequence | |
import itertools | |
import numpy as np | |
OBJECTS = ('1s', '1de', '1pe', '1di', '1pi', | |
'2s', '2d', '2p', | |
'3s.m', '3s.f', '3s.n', |
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
"""Combine https://glottolog.org/langdoc.csv parts.""" | |
import urllib.parse | |
import pandas as pd | |
ENDPOINT = urllib.parse.urlparse('https://glottolog.org/langdoc.csv') | |
QUERY = {'sEcho': 1, | |
'iSortingCols': 1, |
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
"""SQLAlalchemy inserts vs. sqlite3 lazy executemany().""" | |
from collections.abc import Iterator | |
import time | |
import sqlalchemy as sa | |
import sqlalchemy.orm | |
ENGINE = sa.create_engine('sqlite:///spam.sqlite3') |
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
"""Use psycopg2 LoggingConnection with SQLAlalchemy.""" | |
import logging | |
import psycopg2.extras | |
import sqlalchemy as sa | |
logging.basicConfig(level=logging.DEBUG) |
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
"""Find all subclasses of a class with queue or stack.""" | |
import collections | |
from collections.abc import Collection, Iterator | |
def itersubclasses(parent: type, *, | |
proper: bool = True, | |
exclude: Collection[type] = (type,)) -> Iterator[type]: | |
"""Yield `parent` subclasses recursively in breadth-first order.""" |
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
"""More convenient context manager for mmap.mmap.""" | |
from collections.abc import Iterator | |
import contextlib | |
import mmap | |
import os | |
@contextlib.contextmanager | |
def memorymapped_compat(path: os.PathLike | str) -> Iterator[mmap.mmap]: |
OlderNewer