Skip to main content

pyfmr: a python wrapper for FMR

https://github.com/liuzl/fmr

Usage

examples

Install pyfmr via pip

pip install pyfmr

Grammar file

Save the following grammar content to file sf.grammar

<flight> = <departure> <arrival> {nf.flight($1, $2)};
[flight] = <arrival> <departure> {nf.flight($2, $1)};

<departure> = <from> <city> {nf.I($2)};

<arrival> = <to> <city> {nf.I($2)};
[arrival] = <arrival> {nf.arrival($1)};

<from> = "从" ;

<to> = "到" | "去" | "飞";

<city> = "北京"       {nf.I($@)}
       | "天津"       {nf.I($@)}
       | "上海"       {nf.I($@)}
       | "重庆"       {nf.I($@)}
       | `.(?:城|都)` {nf.I($@)}
       ;

<city_ext> = <city>            {nf.I($1)}
           | (any{1,1}) <city> {nf.I($2)}
           ;

<cities> = "直辖市:" (list<city_ext>) {nf.I($@)};

Python example codes

import pyfmr

p = pyfmr.Parser("./sf.grammar")
strs = [
    "直辖市:北京、上海、天津",
    "直辖市:帝都、津城、魔都",
    "中国现在有四个直辖市:帝都、魔都、天津、重庆。",
    "中国曾经的直辖市:帝都、魔都、天津、重庆、旧都。",
    "天津大学",
]
for l in strs:
    ret = p.extract(l, "cities")
    for item in ret:
        print(item)
    print("="*80)

How to build

The cross compiling is done by xgo.

Prerequisites

  • Docker
  • Golang

Steps

# 1. clone the git repo
git clone https://github.com/liuzl/pyfmr && cd pyfmr

# 2. pull xgo docker image
docker pull karalabe/xgo-latest

# 3. install xgo
go get github.com/karalabe/xgo

# 4. build shared libraries
xgo --targets=*/amd64 -buildmode=c-shared -out pyfmr/lib/fmr github.com/liuzl/pyfmr/src

# 5. build wheel
python3 setup.py sdist bdist_wheel

# 6. upload to pypi.org
python3 -m twine upload dist/*

Metadata

Release files for pyfmr 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyfmr 0.0.2
File Size Uploaded
pyfmr-0.0.2.tar.gz 2.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyfmr 0.0.2
File Interpreter ABI Platform
pyfmr-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 16.6 MB

Release files / pyfmr-0.0.2.tar.gz

Download URL pyfmr-0.0.2.tar.gz
Size 2.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ed5fc53f75d09abd59b2a5771e9d0f71dd794aafff72795c0ccabd09cfad39ce
BLAKE2b-256 checksum
How to use checksums
bdf12a06b5312ef719737758eff85abeb41f1daf6fdd91f1c32498aa2f456723
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.9.1 tqdm/4.26.0 CPython/3.7.2

Release files / pyfmr-0.0.2-py3-none-any.whl

Download URL pyfmr-0.0.2-py3-none-any.whl
Size 16.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
52d13f280a3b2badc3da0b3a61bbb9a4e18b4cb4850c7634e549c2f4e4e561a8
BLAKE2b-256 checksum
How to use checksums
db77c8900973a5b2b832079ad84a78be32b0096ad68c7e38f5e241e600bc8de9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.9.1 tqdm/4.26.0 CPython/3.7.2

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page