-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
192 additions
and
860 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ src/**.js | |
coverage | ||
*.log | ||
package-lock.json | ||
yarn.lock | ||
yarn.lock | ||
.DS_Store |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
# Generated files | ||
.docusaurus | ||
.cache-loader | ||
generated | ||
|
||
# Misc | ||
.DS_Store | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import Tree from '../generated/classes/lib_tree.Tree.mdx'; | ||
import Graph from '../generated/classes/lib_graph.Graph.mdx'; | ||
import Triple from '../generated/types/lib_graph.Triple.mdx'; | ||
import PENMANCodec from '../generated/classes/lib_codec.PENMANCodec.mdx'; | ||
|
||
# penman-js | ||
|
||
The main `penman-js` module contains most exports that you'll need for basic usage. For more advanced usage, see the other submodules in the API Reference. | ||
|
||
Users wanting to interact with graphs might find the `decode` and | ||
`encode` functions a good place to start:: | ||
|
||
```js | ||
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'] | ||
|
||
// JS doesn't support keyword parameters, so `undefined` must be passed for optional params | ||
console.log(encode(g, undefined, undefined, 'b')); | ||
// (b / boy | ||
// :ARG0-of (w / want-01 | ||
// :ARG1 (g / go | ||
// :ARG0 b))) | ||
``` | ||
|
||
The `decode` and `encode` functions work with one PENMAN | ||
graph. The `load` and `dump` functions work with | ||
collections of graphs. | ||
|
||
Users who want to work with trees would use `parse` and | ||
`format` instead | ||
|
||
```js | ||
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) | ||
``` | ||
|
||
--- | ||
|
||
<Tree /> | ||
|
||
--- | ||
|
||
<Triple /> | ||
|
||
--- | ||
|
||
<Graph /> | ||
|
||
--- | ||
|
||
<PENMANCodec /> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,27 @@ | ||
--- | ||
sidebar_position: 1 | ||
slug: / | ||
--- | ||
|
||
# Tutorial Intro | ||
# Penman JS | ||
|
||
Let's discover **Docusaurus in less than 5 minutes**. | ||
[![ci](https://img.shields.io/github/actions/workflow/status/chanind/penman-js/ci.yaml?branch=main)](https://github.com/chanind/penman-js) | ||
[![Npm](https://img.shields.io/npm/v/penman-js)](https://www.npmjs.com/package/penman-js) | ||
|
||
## Getting Started | ||
PENMAN notation (e.g. AMR) parser and generator for JavaScript | ||
|
||
Get started by **creating a new site**. | ||
## About | ||
|
||
Or **try Docusaurus immediately** with **[docusaurus.new](https://docusaurus.new)**. | ||
This library is a manual port of the Penman Python library, with identical method names and import structure. However, as Python and Javascript do have some differences, this port has the following changes: | ||
|
||
### What you'll need | ||
- all snake-case function names from the Python library are renamed using camel-case to fit Javascript naming conventions. For example, the function `get_pushed_variable` from Python is renamed to `getPushedVariable` in Javascript. | ||
- Python tuples are replaced with Javascript arrays | ||
- Python dictionaries are replaced with Javascript `Map` | ||
- functions only support positional arguments, since Javascript doesn't support keyword arguments like Python | ||
- All imports use `penman-js` as the base instead of `penman`. For instance, `from penman.graph import Graph` in Python is replaced with `import { Graph } from "penman-js/graph";` in Javascript. | ||
|
||
- [Node.js](https://nodejs.org/en/download/) version 18.0 or above: | ||
- When installing Node.js, you are recommended to check all checkboxes related to dependencies. | ||
Otherwise, refer to the [Penman Python library docs](https://penman.readthedocs.io/en/latest/index.html) for full documentation. | ||
|
||
## Generate a new site | ||
## Disclaimer | ||
|
||
Generate a new Docusaurus site using the **classic template**. | ||
|
||
The classic template will automatically be added to your project after you run the command: | ||
|
||
```bash | ||
npm init docusaurus@latest my-website classic | ||
``` | ||
|
||
You can type this command into Command Prompt, Powershell, Terminal, or any other integrated terminal of your code editor. | ||
|
||
The command also installs all necessary dependencies you need to run Docusaurus. | ||
|
||
## Start your site | ||
|
||
Run the development server: | ||
|
||
```bash | ||
cd my-website | ||
npm run start | ||
``` | ||
|
||
The `cd` command changes the directory you're working with. In order to work with your newly created Docusaurus site, you'll need to navigate the terminal there. | ||
|
||
The `npm run start` command builds your website locally and serves it through a development server, ready for you to view at http://localhost:3000/. | ||
|
||
Open `docs/intro.md` (this page) and edit some lines: the site **reloads automatically** and displays your changes. | ||
This project is not officially affiliated with [AMR](http://amr.isi.edu/) or the [Penman Python library](https://github.com/goodmami/penman). |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
sidebar_position: 2 | ||
--- | ||
|
||
# Quick start | ||
|
||
## Installation | ||
|
||
Install the library from NPM | ||
|
||
``` | ||
npm install penman-js | ||
``` | ||
|
||
## Basic usage | ||
|
||
The `decode` function make it easy to parse AMR text in Penman notation into a graph. The `encode` function can likewise turn it back into a string. | ||
|
||
```js | ||
import { encode, decode } from 'penman-js'; | ||
|
||
g = decode('(b / bark-01 :ARG0 (d / dog))'); | ||
g.triples; | ||
// [('b', ':instance', 'bark-01'), ('b', ':ARG0', 'd'), ('d', ':instance', 'dog')] | ||
g.edges(); | ||
// [Edge(source='b', role=':ARG0', target='d')] | ||
|
||
// JS doesn't support keyword parameters, so `undefined` must be passed for optional params | ||
console.log(encode(g, undefined, undefined, 3)); | ||
// (b / bark-01 | ||
// :ARG0 (d / dog)) | ||
``` |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.