Esempio n. 1
0
string Mykytea::getTagsToString(string str)
{
    KyteaString surface_string = util->mapString(str);
    KyteaSentence sentence(surface_string, util->normalize(surface_string));
    kytea->calculateWS(sentence);

    for(int i = 0; i < config->getNumTags(); i++)
        kytea->calculateTags(sentence,i);

    const KyteaSentence::Words & words =  sentence.words;

    string ret_str;
    for(int i = 0; i < (int)words.size(); i++) {
        ret_str += util->showString(words[i].surface);
        for(int j = 0; j < (int)words[i].tags.size(); j++) {
            for(int k = 0; k < 1; k++) {
                ret_str += "/";
                ret_str += util->showString(words[i].tags[j][k].first);
            }
        }
        ret_str += " ";
    }
    return ret_str;
  
}
Esempio n. 2
0
vector<Tags>* Mykytea::getAllTags(string str){
    vector<Tags>* ret_words = new vector<Tags>;

    KyteaString surface_string = util->mapString(str);
    KyteaSentence sentence(surface_string, util->normalize(surface_string));
    kytea->calculateWS(sentence);

    for(int i = 0; i < config->getNumTags(); i++)
        kytea->calculateTags(sentence,i);

    const KyteaSentence::Words & words =  sentence.words;

    for(int i = 0; i < (int)words.size(); i++) {
        tags vec_tag;
        for(int j = 0; j < (int)words[i].tags.size(); j++) {
            vector< pair<string, double> > vec_tmp;
            for(int k = 0; k < (int)words[i].tags[j].size(); k++) {
                vec_tmp.push_back( make_pair(util->showString(words[i].tags[j][k].first), words[i].tags[j][k].second) );
            }
            vec_tag.push_back( vec_tmp );
        }
        struct Tags t = { util->showString(words[i].surface), vec_tag };
        (*ret_words).push_back( t );
    }
    return ret_words;
}
Esempio n. 3
0
File: main.cpp Progetto: proofy/boss
void blf2xml(const string & file_name, const string & result_name, const string & ext)
{
  ifstream in(file_name.c_str());
  if(!in) {
    cerr << "Warning: Can't open file " << file_name << " ignoring." << endl;
    return;
  }
  ofstream out(result_name.c_str());
  if(!out) {
    cerr << "Warning: Can't open file " << result_name << " ignoring." << endl;
    return;
  }

  c_SentenceEntry sentence(basename(file_name, ext), "#", "#.");

  string tmp;
  vector< c_LabelEntry > label;
  while(getline(in, tmp)) {
    if(!isComment(tmp)) {
      c_LabelEntry tmplabel;
      stringstream ins(tmp.c_str());
      ins >> tmplabel.first >> tmplabel.phon >> tmplabel.pros;
      label.push_back(tmplabel);
    }
  }
Esempio n. 4
0
sp<String> Eliza::talk(sp<String> s) {
    sp<String> reply;
    //  Do some input transformations.
    s = Strings::translate(s, "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
                             "abcdefghijklmnopqrstuvwxyz");
    s = Strings::translate(s, "@#$%^&*()_-+=~`{[}]|:;<>\\\"",
                             "                          "  );
    s = Strings::translate(s, ",?!", "...");
    //  Remove multiple spaces.
    s = Strings::compress(s);
    sp<StringArray> lines = new StringArray(2);
    //  Break apart sentences, and do each separately.
    while (Strings::match(s, "*.*", lines)) {
        reply = sentence(lines->get(0));
        if (reply != nullptr) {
            return reply;
        }
        s = Strings::trim(lines->get(1));
    }
    if (s->length() != 0) {
        reply = sentence(s);
        if (reply != nullptr) {
            return reply;
        }
    }
    //  Nothing matched, so try memory.
    sp<String> m = memory->get();
    if (m != nullptr) {
        return m;
    }

    //  No memory, reply with xnone.
    sp<Key> key = keys->getKey(String::valueOf("xnone"));
    if (key != nullptr) {
        sp<Key> dummy = nullptr;
        reply = decompose(key, s, dummy);
        if (reply != nullptr) {
            return reply;
        }
    }
    //  No xnone, just say anything.
    return String::valueOf("I am at a loss for words.");
}
Esempio n. 5
0
int
main()
{
    
    // declare a new Sentence object and pass "What time is it?" to the 
    // constructor
    Sentence sentence("What time is it???");

    // Call class Sentence's member function print
    sentence.print();

    return 0; // everything executed ok
}
Esempio n. 6
0
vector<string>* Mykytea::getWS(string str){
    vector<string>* vec = new vector<string>;
    KyteaString surface_string = util->mapString(str);
    KyteaSentence sentence(surface_string, util->normalize(surface_string));
    kytea->calculateWS(sentence);

    const KyteaSentence::Words & words =  sentence.words;

    for(int i = 0; i < (int)words.size(); i++) {
         (*vec).push_back(util->showString(words[i].surface));
    }
    return vec;
}
		/**
		 * Finds the sentence annotation containing the given token.
		 *
		 * \param token the token
		 * \return the sentence or an invalid sentence if not found
		 */
		SentenceAnnotation SentenceAnnotation::findSentenceContainingToken(TokenAnnotation& token)
		{
			FSIterator iterator = token.getView().getAnnotationIndex(tSentenceAnnotation).iterator();
			if (iterator.isValid()) {
				iterator.moveToFirst();
				while (iterator.isValid()) {
					AnnotationFS annotation(iterator.get());
					SentenceAnnotation sentence(annotation);
					if ((sentence.getFirstToken().getIndex() <= token.getIndex()) && (sentence.getLastToken().getIndex() >= token.getIndex()))
						return sentence;
					iterator.moveToNext();
				}
			}
			return SentenceAnnotation();
		}
Esempio n. 8
0
Window::Window()
: QGraphicsWidget(0, Qt::Window)
{
    FlowLayout *lay = new FlowLayout;
    QLatin1String wiseWords("I am not bothered by the fact that I am unknown."
    " I am bothered when I do not know others. (Confucius)");
    QString sentence(wiseWords);
    QStringList words = sentence.split(QLatin1Char(' '), QString::SkipEmptyParts);
    for (int i = 0; i < words.count(); ++i) {
        QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(this);
        QLabel *label = new QLabel(words.at(i));
        label->setFrameStyle(QFrame::Box | QFrame::Plain);
        proxy->setWidget(label);
        lay->addItem(proxy);
    }
    setLayout(lay);
}
Esempio n. 9
0
int main()
{
 char ans ;
 
 /*乱数の初期化*/
 srand(65535) ;

 /*文の生成*/
 while(1){
  sentence() ;
  printf("\n") ;
  printf("これで良いですか?(y/n)\n") ;
  scanf("%c",&ans) ;
  if(ans=='y') break ;
}

 return 0 ;
}
JNIEXPORT jint JNICALL Java_edu_hit_ir_ltp4j_Segmentor_segment
  (JNIEnv* env, jobject obj, jstring sent, jobject array_words) {

  jclass array_list = env->GetObjectClass(array_words);
  jmethodID list_add = env->GetMethodID(array_list, "add", "(Ljava/lang/Object;)Z");

  const char* str_sent = env->GetStringUTFChars( sent , 0);
  std::string sentence(str_sent);
  std::vector<std::string> words;

  int len = segmentor_segment(segmentor, sentence, words);

  for(int i = 0; i < len; i++) {
    jobject tmp = stringToJstring(env,words[i].c_str());
    env->CallBooleanMethod(array_words,list_add,tmp);
  }
  env->ReleaseStringUTFChars(sent, str_sent);
  return len;
}
Esempio n. 11
0
void GPSWindow::timeout()
{
	engine::Latitude lat;
	if (!engine::Latitude::parse(lat, latitude->text().toStdString()))
		return;
	engine::Longitude lon;
	if (!engine::Longitude::parse(lon, longitude->text().toStdString()))
		return;
	engine::Date t;
	if (!engine::Date::parse(t, datetime_utc->text().toStdString()))
		return;

	nmea::RMC rmc;
	rmc.set(t);
	rmc.set(lat);
	rmc.set(lon);

	emit sentence(rmc.str());
}
Esempio n. 12
0
int main()
{
 char nlist[NMAX][CHMAX] ;//名詞リスト
 char vlist[NMAX][CHMAX] ;//動詞リスト
 int nnum,vnum ;//リストの項目数
 int i ;
 
 /*乱数の初期化*/
 srand(65535) ;
 /*名詞リストと動詞リストの読み込み*/
 nnum=setlist(nlist,NFILE) ;
 vnum=setlist(vlist,VFILE) ;

 for(i=0;i<50;++i){
  /*文の生成*/
  sentence(nlist,nnum,vlist,vnum) ;
  printf(".\n") ;
}
 return 0 ;
}
Esempio n. 13
0
static void couchStoreAndRetrieveAttachment(PrintTextA &a) {
	CouchDB db(getTestCouch());
	db.use(DATABASENAME);

	Document doc = db.newDocument(".data");
	db.uploadAttachment(doc,"testAttachment","text/plain",[](SeqFileOutput wr) {
		SeqTextOutA txtwr(wr);
		ConstStrA sentence("The quick brown fox jumps over the lazy dog");
		txtwr.blockWrite(sentence,true);
	});

	Document doc2 = db.retrieveDocument(doc.getID());


	AttachmentData data = db.downloadAttachment(doc2,"testAttachment");

	a("%1-%2") << data.contentType << ConstStrA(reinterpret_cast<const char *>(data.data()),data.length());


}
Esempio n. 14
0
void HunspellDialog::goToNextWord(int i)
{
	if (m_returnToDefaultLang)
	{
		bool b=languagesComboBox->blockSignals(true);
		languagesComboBox->setCurrentIndex(m_primaryLangIndex);
		languagesComboBox->blockSignals(b);
	}
	if (i>=0)
		m_wfListIndex=i;
	else
	{
		do {
			++m_wfListIndex;
		} while (m_wfListIndex<m_wfList->count() && (m_wfList->at(m_wfListIndex).changed || m_wfList->at(m_wfListIndex).ignore));
		//qDebug()<<"selected word index"<<m_wfListIndex;
	}
	if (m_wfListIndex>=m_wfList->count())
	{
		statusLabel->setText(tr("Spelling check complete"));
		suggestionsListWidget->clear();
		sentenceTextEdit->clear();
		changePushButton->setEnabled(false);
		changeAllPushButton->setEnabled(false);
		ignoreOncePushButton->setEnabled(false);
		ignoreAllPushButton->setEnabled(false);
		return;
	}
	else
		statusLabel->setText("");
	currWF=m_wfList->at(m_wfListIndex);
	setLanguageCombo(currWF.lang);
	updateSuggestions(currWF.replacements);

	int sentencePos=0;
	QString sentence(m_iText->sentence(currWF.start, sentencePos));
	sentence.insert(currWF.end-sentencePos+currWF.changeOffset,"</b></font>");
	sentence.insert(currWF.start-sentencePos+currWF.changeOffset,"<font color=red><b>");
	sentenceTextEdit->setText(sentence);
}
ISpRecoGrammar* SpeechRecognition::InitGrammar()
{
	HRESULT hr;
	SPSTATEHANDLE sate;

	ISpRecoGrammar* recoGrammar;
	hr = recoContext->CreateGrammar(GRAMMARID, &recoGrammar);
	CheckReturn(hr);

	WORD langID = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
	hr = recoGrammar->ResetGrammar(langID);
	CheckReturn(hr);

	//create rules
	hr = recoGrammar->GetRule(RULENAME, 0, SPRAF_TopLevel | SPRAF_Active, true, &sate);
	CheckReturn(hr);

	//add words
	const std::wstring commandWstr = std::wstring(L"Mocha");
	hr = recoGrammar->AddWordTransition(sate, NULL, commandWstr.c_str(), L" ", SPWT_LEXICAL, 1, nullptr);
	CheckReturn(hr);

	for (std::wstring& ws : wordList)
	{
		std::string sentence(ws.begin(), ws.end());
		std::vector<std::string> words = split(sentence, ' ');
		for (std::string& w : words)
		{
			std::wstring wsword(w.begin(), w.end());
			hr = recoGrammar->AddWordTransition(sate, NULL, wsword.c_str(), L" ", SPWT_LEXICAL, 1, nullptr);
		}
		CheckReturn(hr);
	}
	
	hr = recoGrammar->Commit(0);
	CheckReturn(hr);

	return recoGrammar;
}
Esempio n. 16
0
void MainWindow::updateNavInfoEvent()
{

    QString buff;
    port->receiveLine(buff);
    GpSentence sentence(buff);
    ui->textBrowser->append("GPXXX:" + sentence.code);

    if(sentence.code.contains("$GPRMC")) {
        if(sentence.data.size() >=8 ) {
            infoA->text = sentence.data[6];
            infoD->text = sentence.data[7];
        }
    }


    if(sentence.code.contains("$GPGGA")) {
        if(sentence.data.size() >=9 ) {
            infoB->text = sentence.data[8];
            QString lat = sentence.data[1]+ " " +sentence.data[2];
            QString lon = sentence.data[3]+ " " +sentence.data[4];
            ui->lineEdit->setText("LAT: " + lat + " LON:" + lon);
        }
    }




//  ui->textBrowser->append(buff);
    //     ui->textBrowser->ensureCursorVisible();


    // infoA->text = NavInfo::Instance()->getSpeedString();

    repaint();
}
Esempio n. 17
0
void Samu::FamilyCaregiverShell ( void )
{
  std::string cmd_prefix = "cmd";

  fd_set rfds;
  struct timeval tmo;

  int sleep {0};

  if ( sleep_ )
    sleep = sleep_after_ + 1;

  int prev_sec {0};
  for ( ; run_ ; )
    {

      try
        {

          disp.cg_read();

          if ( ++sleep > sleep_after_ )
            {
              if ( !sleep_ )
                {
                  std::cerr << "Isaac went to sleep." << std::endl;
                  disp.log ( "I went to sleep." );
                }
              sleep_ = true;
            }
          else
            {
              std::cerr << sleep << " " << std::flush;

              int sec = ( sleep * read_usec_ ) / ( 1000*1000 );
              if ( sec != prev_sec )
                {
                  int after = ( sleep_after_ * read_usec_ ) / ( 1000*1000 );

                  std::stringstream sleep_after;

                  sleep_after << "I will go to sleep after ";
                  sleep_after << ( after-sec );
                  sleep_after <<  " seconds";

                  disp.log ( sleep_after.str() );
                  prev_sec = sec;
                }
            }
        }
      catch ( std::string line )
        {

          if ( sleep_ )
            {
              std::cerr << "Isaac is awake now." << std::endl;
              disp.log ( "I am awake now." );
            }
          sleep_ = false;
          sleep = 0;

          if ( !line.compare ( 0, cmd_prefix.length(), cmd_prefix ) )
            {
              std::string readCmd {"cmd read"};

              size_t f = line.find ( readCmd );
              if ( f != std::string::npos )
                {
                  f = f+readCmd.length() +1;
                  if ( f < line.length() )
                    {
                      std::string fname = line.substr ( f );
                      set_training_file ( fname );
                    }
                }
              else
                NextCaregiver();
            }
          else
            {
              try
                {
                  sentence ( -1, line );
                }
              catch ( const char* err )
                {
                  std::cerr << err << std::endl;
                  disp.log ( err );
                }
            }
        }

      usleep ( read_usec_ );

    }

  run_ = false;
}
void DataBlock::Add(int *head, int sentence_length, int64_t word_count, uint64_t next_random)
{
	Sentence sentence(head, sentence_length, word_count, next_random);
	m_sentences.push_back(sentence);
}
Esempio n. 19
0
int main(int argc, char *argv[]) /*{{{*/
{
  int usage=0,c;
  char *userPhrases=(char*)0,*e;
  char defaultPhrases[_POSIX_PATH_MAX];
  static struct option lopts[]=
  {
    { "beginner", no_argument, 0, 'b', },
    { "ignore-double-words", no_argument, 0, 'd' },
    { "suggest", no_argument, 0, 's' },
    { "file", required_argument, 0, 'f' },
    { "help", no_argument, 0, 'h' },
    { "version", no_argument, 0, 'v' },
    { "language", required_argument, 0, 'L' },
    { "quiet", no_argument, 0, 'q' },
    { "no-default-file", no_argument, 0, 'n' },
    { (const char*)0, 0, 0, '\0' }
  };

  /* init locale */ /*{{{*/
  setlocale(LC_ALL,"");
#ifdef HAVE_GETTEXT
  bindtextdomain("diction",LOCALEDIR);
  textdomain("diction");
#endif
  e=getenv("LC_MESSAGES");
  if (e==(char*)0) e=getenv("LC_ALL");
  if (e==(char*)0) e=getenv("LANG");
  if (e)
  {
    strncpy(phraseLanguage,e,sizeof(phraseLanguage)-1);
    phraseLanguage[sizeof(phraseLanguage)-1]='\0';
    if (strstr(phraseLanguage,".."))
    {
      fprintf(stderr,_("diction: Invalid string `..' in default phrase language `%s'.\n"),phraseLanguage);
      exit(2);
    }
    else
    {
      snprintf(defaultPhrases,sizeof(defaultPhrases), "/diction/%s",e);
      if (access(defaultPhrases,R_OK)!=0)
      {
        phraseLanguage[5]='\0';
        snprintf(defaultPhrases,sizeof(defaultPhrases), "/diction/%s",phraseLanguage);
        if (access(defaultPhrases,R_OK)!=0)
        {
          phraseLanguage[2]='\0';
          snprintf(defaultPhrases,sizeof(defaultPhrases), "/diction/%s",phraseLanguage);
          if (access(defaultPhrases,R_OK)!=0)
          {
            strcpy(phraseLanguage,"C");
          }
        }
      }
    }
  }
  else strcpy(phraseLanguage,"C");
  /*}}}*/
  /* parse options */ /*{{{*/
  strcpy(defaultPhrases, "/diction/");
  while ((c=getopt_long(argc,argv,"bdsf:nL:qh",lopts,(int*)0))!=EOF) switch(c)
  {
    case 'b': beginner=1; break;
    case 'd': doubleWords=0; break;
    case 's': suggest=1; break;
    case 'f': userPhrases=optarg; break;
    case 'n': defaultPhrases[0]='\0'; break;
    case 'L': strncpy(phraseLanguage,optarg,sizeof(phraseLanguage)-1); phraseLanguage[sizeof(phraseLanguage)-1]='\0'; break;
    case 'q': quiet=1; break;
    case 'v': printf("GNU diction\n"); exit(0);
    case 'h': usage=2; break;
    default: usage=1; break;
  }
  if (defaultPhrases[0]) strcat(defaultPhrases,phraseLanguage);
  if (usage==1 || (userPhrases==(char*)0 && defaultPhrases[0]=='\0'))
  {
    print_usage(stderr);
    fputs("\n",stderr);
    fputs(_("Try `diction -h' or `diction --help' for more information.\n"),stderr);
    exit(1);
  }
  if (usage==2)
  {
    print_usage(stdout);
    fputs("\n",stdout);
    fputs(_("Print wordy and commonly misused phrases in sentences.\n\n"),stdout);
    fputs(_("-b, --beginner             complain about typical mistakes of beginners\n"),stdout);
    fputs(_("-d, --ignore-double-words  do not complain about double words\n"),stdout);
    fputs(_("-s, --suggest              suggest better wording\n"),stdout);
    fputs(_("-f, --file                 also read the specified database\n"),stdout);
    fputs(_("-n, --no-default-file      do not read the default phrase file\n"),stdout);
    fputs(_("-L, --language             set document language\n"),stdout);
    fputs(_("-q, --quiet                do not print input file name\n"),stdout);
    fputs(_("-h, --help                 print this message\n"),stdout);
    fputs(_("    --version              print the version\n"),stdout);
    fputs("\n",stdout);
    fputs(_("Report bugs to <*****@*****.**>.\n"),stdout);
    exit(0);
  }
  /*}}}*/
  if (defaultPhrases[0]) loadPhrases(defaultPhrases);
  if (userPhrases) loadPhrases(userPhrases);
  sentences=0;
  hits=0;
  if (optind==argc) sentence("diction",stdin,"(stdin)",diction,phraseLanguage);
  else while (optind<argc)
  {
    FILE *fp;

    if ((fp=fopen(argv[optind],"r"))==(FILE*)0)
    {
      fprintf(stderr,_("diction: Opening `%s' failed (%s).\n"),argv[optind],strerror(errno));
    }
    else
    {
      sentence("diction",fp,argv[optind],diction,phraseLanguage);
      fclose(fp);
    }
    ++optind;
  }
  if (sentences==0)
  {
    printf(_("No sentences found.\n"));
  }
  else
  {
    if (hits==0) printf(_("No phrases "));
    else if (hits==1) printf(_("1 phrase "));
    else printf(_("%d phrases "),hits);
    if (sentences==1) printf(_("in 1 sentence found.\n"));
    else printf(_("in %d sentences found.\n"),sentences);
  }
  exit(0);
}
Esempio n. 20
0
  TranslationHypothesis::TranslationHypothesis(const string& source) 
    {

    const StaticData &staticData = StaticData::Instance();
    const TranslationSystem& system = 
      staticData.GetTranslationSystem(TranslationSystem::DEFAULT);

    //clean up previous sentence
    if (m_cleanup) {
      system.CleanUpAfterSentenceProcessing();
    } else {
      m_cleanup = true;
    }
    
    //the sentence
    Sentence sentence(Input);
    stringstream in(source + "\n");
    const std::vector<FactorType> &inputFactorOrder = staticData.GetInputFactorOrder();
    sentence.Read(in,inputFactorOrder);
    for (size_t i=0; i<sentence.GetSize(); ++i){ m_words.push_back(sentence.GetWord(i)); } 

    //translation options
    m_manager.reset(new Manager(sentence, Normal, &system));
    m_manager->ResetSentenceStats(sentence);
    system.InitializeBeforeSentenceProcessing(sentence);
    m_toc.reset(sentence.CreateTranslationOptionCollection(&system));
    //const vector <DecodeGraph*>
    //      &decodeStepVL = staticData.GetDecodeGraphs();
    m_toc->CreateTranslationOptions();

    //sort the options
    size_t maxPhraseSize = staticData.GetMaxPhraseLength();
    for (size_t start = 0; start < m_words.size(); ++start) {
      for (size_t end = start; end < start + maxPhraseSize && end < m_words.size(); ++end) {
        TranslationOptionList& options = 
          m_toc->GetTranslationOptionList(start,end);
        sort(options.begin(), options.end(), TOptCompare());
        /*
        while (options.size() > ttableLimit) {
          size_t pos = options.size() - 1;
          delete options.Get(pos);
          options.Remove(pos); 
        }*/
      }
    }

    //hypothesis
    m_hypothesis.reset(Hypothesis::Create(*m_manager,sentence, emptyTarget()));
    for (size_t i = 0; i < m_words.size(); ++i) {
      m_allHypos.push_back(m_hypothesis);
      WordsRange segment(i,i);
      const TranslationOptionList& options = 
        m_toc->GetTranslationOptionList(segment);
      
      
      /*
      cerr << "Options for " << *(options.Get(0)->GetSourcePhrase()) << endl;
      for (size_t j = 0; j < options.size(); ++j) {
        cerr << *(options.Get(j)) << endl;
      }*/
      assert(options.size());
      m_hypothesis.reset(
        Hypothesis::Create(*m_hypothesis, *(options.Get(0)), NULL)); 
    }
}