void CRF::classify(const FunctionCallbackInfo<Value>& args){ Isolate* isolate = args.GetIsolate(); CRF* obj = (CRF *) ObjectWrap::Unwrap<CRF>(args.Holder()); v8::Persistent<v8::External, v8::CopyablePersistentTraits<v8::External> > tagger = obj->tagger; v8::Local<v8::External> handle = v8::Local<v8::External>::New(isolate, tagger); CRFPP::Tagger *a = (CRFPP::Tagger *) handle->Value(); if (a==NULL) { fprintf(stderr,"No tagger. Exiting...\n"); return; } a->clear(); Local<Array> arr = Local<Array>::Cast(args[0]); int size = arr->Length(); for(int i=0;i<size;i++){ Local<Value> element = arr->Get(i); char* c = get(element); a->add(c); // each iteration, free memory free(c); c = NULL; } bool isParsed = a->parse(); if ( isParsed == false) { fprintf(stderr,"Failed to parse.\n"); } Local<Array> solutions = Array::New(isolate, a->nbest()); unsigned int count = 0; while (count < a->nbest()) { Local<Array> s = Array::New(isolate, a->ysize()); for (size_t i = 0; i < a->size(); ++i) { s -> Set(i,Local<Value>(String::NewFromUtf8(isolate, a->y2(i)))); } solutions -> Set(count, s); a->next(); count++; } args.GetReturnValue().Set(solutions); };
Handle<Value> CRF::classify(const Arguments& args){ HandleScope scope; Local<Array> arr = Local<Array>::Cast(args[0]); CRF* obj = ObjectWrap::Unwrap<CRF>(args.This()); CRFPP::Tagger *a = *(obj->tagger); a->clear(); int size = arr->Length(); for(int i=0;i<size;i++){ Local<Value> element = arr->Get(i); char* c = get(element); a->add(c); // each iteration, free memory free(c); c = NULL; } a->parse(); Local<Array> solutions = Array::New(a->nbest()); unsigned int count = 0; while (count < a->nbest()) { Local<Array> s = Array::New(a->ysize()); for (size_t i = 0; i < a->size(); ++i) { s -> Set(i,Local<Value>(String::New(a->y2(i)))); } solutions -> Set(count, s); a->next(); count++; } return scope.Close(solutions); };