Created
July 19, 2021 20:09
-
-
Save cthoyt/05e3eb573789f646bcc8e28e0d48aa50 to your computer and use it in GitHub Desktop.
PyKEEN tweet generator
This file contains hidden or 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 PyKEEN model tweets.""" | |
from textwrap import dedent | |
import click | |
from docdata import get_docdata | |
from pykeen.models import model_resolver | |
@click.command() | |
@click.argument('name') # the name of the model | |
@click.option('--pr', help='The pull request number to include a "Code" link') | |
@click.option('--force', is_flag=True, help='Output options even if they exceed the tweet character length limit') | |
def main(name: str, pr=None, force: bool = False): | |
"""Generate PyKEEN new model tweets!""" | |
model_cls = model_resolver.lookup(name) | |
model_docdata = get_docdata(model_cls) | |
name = model_docdata.get('name', model_cls.__name__) | |
cite = model_docdata['citation'] | |
s = dedent(f'''\ | |
PyKEEN now implements {name} from {cite['author']} et al ({cite['year']})! | |
π Paper: {cite['link']} | |
''') | |
usage = dedent(f'''\ | |
π Usage: | |
>>> from pykeen.pipeline import pipeline | |
>>> pipeline(model='{model_cls.__name__}', dataset='FB15k')\n | |
''') | |
if force or (len(s) + len(usage) <= 280): | |
s += usage | |
docs = f'π Docs: https://pykeen.rtfd.io/en/latest/api/pykeen.models.{model_cls.__name__}.html\n\n' | |
if force or (len(s) + len(docs) <= 280): | |
s += docs | |
if pr is not None: | |
code = f'π₯οΈ Code: https://github.com/pykeen/pykeen/pull/{pr}\n' | |
if force or (len(s) + len(code) <= 280): | |
s += code | |
print(s) | |
print(f'Length:', len(s)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment