1.1.0 • Published 1 year ago

bareun v1.1.0

Weekly downloads
-
License
BSD 3-Clause
Repository
github
Last release
1 year ago

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:
NameTypeDescription
remoteStringhost + ":" + port. ex)"nlp.bareun.ai:5656".
AnalyzeSyntax( text, domain = null, auto_split = false, callback = null )

Analyze text.

Parameters:
NameTypeDescription
textString
domainStringdomain custom dictionary name.
auto_splitBoolean
callbackFunction(error, response)
async asyncAnalyzeSyntax(text, domain = null, auto_split = false )

Analyze text.

Parameters:
NameTypeDescription
textString
domainStringdomain custom dictionary name.
auto_splitBoolean
Returns:

Object<AnalyzeSyntaxResponse> AnalyzeSyntaxResponse object.

class Tagger

Methods

constructor(host="nlp.bareun.ai", port=5656, domain=null)
Parameters:
NameTypeDescription
hostStringbareun server address. default: ENV BAREUN_HOST or "nlp.bareun.ai"
portIntegerbareun server port. default: ENV BAREUN_PORT or 5656
domainStringdomain custom dictionary name.
set_domain(domain)

Set current domain custom dictionary name.

Parameters:
NameTypeDescription
domainStringdomain custom dictionary name.
custom_dict(domain)

Get custom dictionary

Parameters:
NameTypeDescription
domainStringdomain custom dictionary name.
Returns:

Object<CustomDict> Custom dictionary object.

async tag(phrase, auto_split = false)
Parameters:
NameTypeDescription
phraseString
auto_splitBoolean
Returns:

Object<Tagged> Tagged object.

async pos(phrase, flatten = true, join=false, detail=false)
Parameters:
NameTypeDescription
phraseString
flattenBoolean
joinBoolean
detailBoolean
Returns:

Array<Any>

async morphs(phrase)

Get morphs array of phrase.

Parameters:
NameTypeDescription
phraseString
Returns:

Array<String> String array.

async nouns(phrase)

Get nouns array of phrase.

Parameters:
NameTypeDescription
phraseString
Returns:

Array<String> String array.

async verbs(phrase)

Get verbs array of phrase.

Parameters:
NameTypeDescription
phraseString
Returns:

Array<String> String array.

class Tagged

Methods

constructor(phrase, res)
Parameters:
NameTypeDescription
phraseString
resObject<AnalyzeSyntaxResponse>AnalyzeSyntaxResponse object
msg()

Get AnalyzeSyntaxResponse object

Returns:

Object<AnalyzeSyntaxResponse> AnalyzeSyntaxResponse object.

as_json_str(beauty = false)

Get json string for AnalyzeSyntaxResponse object

Parameters:
NameTypeDescription
beautyBoolean
print_as_json(out = console)

Print json string for AnalyzeSyntaxResponse object

Parameters:
NameTypeDescription
outconsole, Object<Stream>
pos(phrase, flatten = true, join=false, detail=false)
Parameters:
NameTypeDescription
flattenBoolean
joinBoolean
detailBoolean
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

1.1.0

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago