0.0.3 • Published 7 years ago

react-nlp v0.0.3

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

react-nlp

Visualization of Natural Language Processing for React

Installation

npm install react-nlp

Usage

import React from "react";
import { render } from "react-dom";
import { View } from "react-nlp";

render(
  <View
    types={types}
    data={data}
    colors={colors}
  />,
  document.getElementById("root")
);

Properties of View Component

PropertyTypeOptionalDefaultDescription
typesArrayNo-Annotation type list
dataArrayNo-Text and annotation data
reationsArrayYes-Relation list
colorsObjectYes-Color map for annotation labels
linumbooleanYestrueIf true, show line numbers
lineBreakbooleanYestrueIf true, enable line break
keepWhiteSpacesbooleanYesfalseIf true, show multiple consecutive whitespace
themeObjectYes-Override the defaultTheme

types

The types is an array of annotation type to show.

The annotations are shown in the order of types.

example:

["wiki", "ne", "pos"]

data

The data is an array of the object consists of a text and annotation data .

PropertyTypeOptionalDescription
data[].textstringNoText
data[].annoArrayNoAnnotation data for the text
data[].annostringNoAnnotation type
data[].annonumberNoStart index of the text to annotate
data[].annonumberNoEnd index of the text to annotate
data[].annostringNoAnnotation label

example:

[
  {
    text: "Darth Vador, also known as Anakin Skywalker is a fictional character.",
    anno: [
      ["wiki", 0, 10, "Darth_Vador"],
      ["wiki", 27, 41, "Darth_Vador"],
      ["ne", 0, 10, "PERSON"],
      ["ne", 27, 41, "PERSON"],
      ["pos", 0, 4, "NNP"],
      ["pos", 6, 10, "NNP"],
      ["pos", 11, 11, ","]
    ]
  },
  {
    text: "He is originally a good person, but",
    anno: [
      ["pos", 0, 1, "PRP"],
      ["pos", 3, 4, "VBZ"],
      ["pos", 6, 15, "RB"],
      ["pos", 17, 17, "DT"],
    ]
  }
]

relations

The relations is a list of relation of annotations.

PropertyTypeOptionalDescription
realationsstringNoType of relationtt: tail-tail relation (-)ht: head-tail relation (←)th: tail-head relation (→)hh: head-head relation (↔)
realationsnumberNoFirst sentence index
realationsnumberNoFirst span index
realationsnumberNoSecond sentence index
realationsnumberNoSecond span index
realationsstringNoRelation label

example:

[
  ["hh", 0, 0, 0, 1, "rel_label1"],
  ["ht", 0, 0, 0, 2, "rel_label2"],
  ["tt", 0, 0, 1, 0, "rel_label3"],
  ["hh", 0, 0, 1, 7, "rel_label4"]
]

colors

The colors is a map for colors for annotation labels.

example:

{
  "wiki": {
    "Darth_Vador": "gray"
  },
  "ne": {
    "PERSON": "yellow"
  },
  "pos": {
    ",": "#84b62b"
  }
}

theme

PropertyTypeDefaultDescription
fontSizestring|number14text font size
borderStylenumber10: none, 1: full, 2: simple
borderstring"solid 1px #9a9a9a"css border format
colorstring"black"text font color
linumColorstring"#9a9a9a"linum color
stripebooleantrueenable/disable stripe
stripeColorArray["#ffffff", "#f2f2f2"]stripe color
linePaddingstring|number"15px 5px"line padding
annotationLinePaddingstring|number"2px 3px"annotation line padding
labelFontSizestring|number"0.6em"label font size
labelColorstring"black"label color
labelPaddingstring"2px 3px"label padding
labelBorderstring"solid 1px gray"label border
characterPaddingstring|number0character left-right padding
relationColorstring"black"relation color
relationLabelFontSizestring|number"12px"relation label font size
relationLabelPaddingstring|number"2px 3px"relation label padding
relationLabelBorderstring"solid 1px gray"relation label border
relationLabelColorstring"black"relation label color
relationLabelBgColorstring"lightblue"relation label background color
relationLabelBorderRadiusstring|number"0px"relation label border radius

Run Example

npm install
npm install react react-dom
npm run build
npm run example

Then, access http://localhost:8080/ in your browser.

If enable Server Mode, access http://localhost:8080/?server=yes.

Run Demo App

npm install
npm install react react-dom
npm run build
npm run demo

Then, access http://localhost:8080/ in your browser.

Dependencies

  • react
  • react-dom
  • css-element-queries
  • color

License

MIT