Code Monkey home page Code Monkey logo

penman-js's Introduction

penman-js

ci Npm

Javascript port of the Penman Python library for Abstract Meaning Representation (AMR).

Full docs: https://chanind.github.io/penman-js

About

This library, including documentation, is a manual port of the Penman Python library. All functionality available in the original library should also be available in this library, with similar usage and semantics. The Python library should still be considered the main project for new features. If you find that behavior differs between these libraries, please open a Github issue.

The goal of this project is to bring the power of the Penman Python library's AMR parsing and generation to the browser and Node.js. This project does not provide a CLI interface for manipulating AMR, since the Python library already provides that functionality.

Installation

Installation is via NPM:

npm install penman-js

Basic usage

The most faithful representation of AMR text in the library is the Tree class. The parse function turns an AMR text string into a Tree, and format does the reverse, turning a Tree back into a string.

import { parse, format } from 'penman-js';

const t = penman.parse('(w / want-01 :ARG0 (b / boy) :ARG1 (g / go :ARG0 b))');
const [variable, branches] = t.node;
console.log(variable); // ouput: 'w'
console.log(branches.length); // output: 3
const [role, target] = branches[2];
console.log(role); // output: ':ARG1'
console.log(format(target));
// (g / go
//     :ARG0 b)

Users wanting to interact with graphs might find the decode and encode functions a good place to start.

import { encode, decode } from 'penman-js';
const g = penman.decode('(w / want-01 :ARG0 (b / boy) :ARG1 (g / go :ARG0 b))');
console.log(g.top);
// 'w'
console.log(g.triples.length);
// 6
console.log(g.instances().map((instance) => instance[2]));
// ['want-01', 'boy', 'go']

console.log(encode(g, { top: 'b' }));
// (b / boy
//    :ARG0-of (w / want-01
//                :ARG1 (g / go
//                         :ARG0 b)))

See https://chanind.github.io/penman-js for full docs.

Contributing

Contributions are welcome! If you notice any bugs or have ideas for improvements, please either file an issue or open a pull request.

Development

This project is written in Typescript, using yarn for dependency management, eslint for linting, and ava for tests. Install dependencies with yarn install. To run linting and tests, run yarn test.

Acknowledgements

This library, including documentation, is a manual port of the Penman Python library, and as such, all credit for the original code and docs work goes to github.com/goodmami/penman.

penman-js's People

Contributors

chanind avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.