npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bareun

v1.1.0

Published

Javascript client for bareun

Downloads

9

Readme

bareun

What is this?

bareun is the javascript library for bareun.

Bareun is a Korean NLP, which provides tokenizing, POS tagging for Korean.

Installation

This is a Node.js module available through the npm registry. It can be installed using the npm or yarn command line tools.

npm install bareun --save

How to get bareun server

  • Go to https://bareun.ai/.
    • With registration, for the first time, you can get a free license for 3 months.
    • If you are a student or a researcher, you can get also a free license for 1 year, which is able to renew after 1 year.
  • Or use docker image.
docker pull bareunai/bareun:latest

Envrionment values

  • BAREUN_HOST : Default address of bareun server ( default: "nlp.bareun.ai" )
  • BAREUN_PORT : Default port of bareun server ( default: 5656 )
  • you can set this ENV values in the .env file in your project root directory.

classes

class LanguageServiceClient

Methods

constructor(remote=null)
Parameters:

| Name | Type | Description | |---|:---:|:---:| | remote | String | host + ":" + port. ex)"nlp.bareun.ai:5656". |

AnalyzeSyntax( text, domain = null, auto_split = false, callback = null )

Analyze text.

Parameters:

| Name | Type | Description | |---|:---:|:---:| | text | String | | | domain | String | domain custom dictionary name. | | auto_split | Boolean | | | callback | Function(error, response) | |

async asyncAnalyzeSyntax(text, domain = null, auto_split = false )

Analyze text.

Parameters:

| Name | Type | Description | |---|:---:|:---:| | text | String | | | domain | String | domain custom dictionary name. | | auto_split | Boolean | |

Returns:

Object<AnalyzeSyntaxResponse> AnalyzeSyntaxResponse object.

class Tagger

Methods

constructor(host="nlp.bareun.ai", port=5656, domain=null)
Parameters:

| Name | Type | Description | |---|:---:|:---:| | host | String | bareun server address. default: ENV BAREUN_HOST or "nlp.bareun.ai" | | port | Integer | bareun server port. default: ENV BAREUN_PORT or 5656 | | domain | String | domain custom dictionary name. |

set_domain(domain)

Set current domain custom dictionary name.

Parameters:

| Name | Type | Description | |---|:---:|:---:| | domain | String | domain custom dictionary name. |

custom_dict(domain)

Get custom dictionary

Parameters:

| Name | Type | Description | |---|:---:|:---:| | domain | String | domain custom dictionary name. |

Returns:

Object<CustomDict> Custom dictionary object.

async tag(phrase, auto_split = false)
Parameters:

| Name | Type | Description | |---|:---:|:---:| | phrase | String | | | auto_split | Boolean |

Returns:

Object<Tagged> Tagged object.

async pos(phrase, flatten = true, join=false, detail=false)
Parameters:

| Name | Type | Description | |---|:---:|:---:| | phrase | String | | | flatten | Boolean | | | join | Boolean | | | detail | Boolean | |

Returns:

Array<Any>

async morphs(phrase)

Get morphs array of phrase.

Parameters:

| Name | Type | Description | |---|:---:|:---:| | phrase | String | |

Returns:

Array<String> String array.

async nouns(phrase)

Get nouns array of phrase.

Parameters:

| Name | Type | Description | |---|:---:|:---:| | phrase | String | |

Returns:

Array<String> String array.

async verbs(phrase)

Get verbs array of phrase.

Parameters:

| Name | Type | Description | |---|:---:|:---:| | phrase | String | |

Returns:

Array<String> String array.

class Tagged

Methods

constructor(phrase, res)
Parameters:

| Name | Type | Description | |---|:---:|:---:| | phrase | String | | | res | Object<AnalyzeSyntaxResponse> | AnalyzeSyntaxResponse object |

msg()

Get AnalyzeSyntaxResponse object

Returns:

Object<AnalyzeSyntaxResponse> AnalyzeSyntaxResponse object.

as_json_str(beauty = false)

Get json string for AnalyzeSyntaxResponse object

Parameters:

| Name | Type | Description | |---|:---:|:---:| | beauty | Boolean | |

print_as_json(out = console)

Print json string for AnalyzeSyntaxResponse object

Parameters:

| Name | Type | Description | |---|:---:|:---:| | out | console, Object<Stream> | |

pos(phrase, flatten = true, join=false, detail=false)
Parameters:

| Name | Type | Description | |---|:---:|:---:| | flatten | Boolean | | | join | Boolean | | | detail | Boolean | |

Returns:

Array<Any>

morphs()

Get morphs array of phrase.

Returns:

Array<String> String array.

nouns()

Get nouns array of phrase.

Returns:

Array<String> String array.

verbs()

Get verbs array of phrase.

Returns:

Array<String> String array.

How to use

    let host="nlp.bareun.ai"
    let {LanguageServiceClient, Tagger, CustomDict}  = require("bareun");
    let language_service_client = new LanguageServiceClient(host);

    language_service_client.AnalyzeSyntax("아버지가 방에 들어가신다.",
        (error, res) => {
            console.log('result : language_service_client.AnalyzeSyntax("아버지가 방에 들어가신다.")');
            if( error ) {            
                throw error;            
                return;
            }                 
            console.log(JSON.stringify(res));        
        }
    );

    (async () => {
      try {  
          let res = await language_service_client.asyncAnalyzeSyntax("아버지가 방에 들어가신다.")        
          console.log(JSON.stringify(res));    
      } catch(e) {
          console.log(e);       
      } 
    })();

    
    let tagged = await tagger.tag("미친 세상에서 맨정신으로 산다는 건 힘든 일이다.");
    (async () => {
        const t=true, f=false;
        let obj;
        obj = tagged.pos(t, t, t);
        console.log("pos(t, t, t)"+JSON.stringify(obj));
        
        obj = tagged.pos(t, t, f);
        console.log("pos(t, t, f)"+JSON.stringify(obj));

        obj = tagged.pos(t, f, t);
        console.log("pos(t, f, t)"+JSON.stringify(obj));

        obj = tagged.pos(f, t, t);
        console.log("pos(f, t, t)"+JSON.stringify(obj));

        obj = tagged.morphs();
        console.log("morphs()"+JSON.stringify(obj));

        obj = tagged.nouns();
        console.log("nouns()"+JSON.stringify(obj));

        obj = tagged.verbs();
        console.log("verbs()"+JSON.stringify(obj));
    })(); 


    let dict = new CustomDict("game", host);

    (async () => {
        let set = new Set(["지지", "캐리", "던전", "현피", "세계관", "만렙","어그로","치트키","퀘스트","본캐","로밍","방사","딜러","버스","사플" ] );
        dict.copy_cp_set(set);

        let success = await dict.update();
        console.log("result :  dict.update() - " + success);
        
        await dict.read_np_set_from_file(__dirname + "/game_dict.txt");
        console.log("result :  dict.load() - " + JSON.stringify([...dict.word_sets.np_set]));   
        let success = await dict.update();
        console.log("result :  dict.update() - " + success);     

        let res = await dict.client.async_get_list();
        console.log("async_get_list() : " + JSON.stringify(res, null, 2));

        await dict.load();

        let res = await dict.clear();
        console.log("clear() : " + JSON.stringify(res, null, 2));
    })();

License

BSD 3-Clause License