示例#1
0
std::string EnglishSpelling::spell(int number)
{
	int n = number;

	return boost::trim_copy(words(n / 1000000, " million " + _and (n % 1000000)) +
		words((n % 1000000) / 1000, " thousand " + _and (n % 1000)) + words(n % 1000, ""));
}
    bool remove(uint element) {
      uint word_index = IndexSet::get_word_index(element);
      uint bit_index = IndexSet::get_bit_index(element);

      uint32 bit = (0x1 << bit_index);
      uint32 before = words()[word_index];
      words()[word_index] = before & ~bit;
      return ((before & bit) != 0);
    }
示例#3
0
void mpfx_manager::set(mpfx & n, mpfx const & v) {
    if (is_zero(v)) {
        reset(n);
        return;
    }
    allocate_if_needed(n);
    n.m_sign      = v.m_sign;
    unsigned * w1 = words(n);
    unsigned * w2 = words(v);
    for (unsigned i = 0; i < m_total_sz; i++)
        w1[i] = w2[i];
    SASSERT(check(n));
}
示例#4
0
bool mpfx_manager::eq(mpfx const & a, mpfx const & b) const {
    if (is_zero(a) && is_zero(b))
        return true;
    if (is_zero(a) || is_zero(b))
        return false;
    if (a.m_sign     != b.m_sign) 
        return false;
    unsigned * w1 = words(a);
    unsigned * w2 = words(b);
    for (unsigned i = 0; i < m_total_sz; i++) 
        if (w1[i] != w2[i])
            return false;
    return true;
}
示例#5
0
文件: words.c 项目: wayneiny/algo
void words(char *arr){
	//base case 1
	if (!(*arr))
		return;
	//base case 2
	if (*arr==' '){
		printf("\n");
		words(arr+1);
	}
	else {	
		printf("%c",*arr);
		words(arr+1);
	}
}
示例#6
0
文件: main.cpp 项目: kevinclark/kata
std::string FindWord(const trie_type& trie, const std::string& keys, size_t alternative)
{
    typedef std::vector<Word>   Words;

    trie_type::result_type candidates = trie.find(keys);
    
    Words::const_iterator match;
    Words words(candidates.first, candidates.second);
    std::sort(words.begin(), words.end(), boost::mem_fn(&Word::MoreFrequent));

    for (Words::const_iterator word = words.begin(); word != words.end(); ++word)
    {
        match = word;

        if (alternative == 0)
        {
            break;
        }
        else
        {
            --alternative;
        }
    }

    if (match == words.end())
    {
        return "No alternative";
    }
    else
    {
        return match->str();
    }
}
示例#7
0
// Compile code in boot image so that we can execute the startup quotation
// Allocates memory
void factor_vm::prepare_boot_image() {
  std::cout << "*** Stage 2 early init... " << std::flush;

  // Compile all words.
  data_root<array> words(instances(WORD_TYPE), this);

  cell n_words = array_capacity(words.untagged());
  for (cell i = 0; i < n_words; i++) {
    data_root<word> word(array_nth(words.untagged(), i), this);

    FACTOR_ASSERT(!word->entry_point);
    jit_compile_word(word.value(), word->def, false);
  }
  update_code_heap_words(true);

  // Initialize all quotations
  data_root<array> quotations(instances(QUOTATION_TYPE), this);

  cell n_quots = array_capacity(quotations.untagged());
  for (cell i = 0; i < n_quots; i++) {
    data_root<quotation> quot(array_nth(quotations.untagged(), i), this);

    if (!quot->entry_point)
      quot->entry_point = lazy_jit_compile_entry_point();
  }

  special_objects[OBJ_STAGE2] = special_objects[OBJ_CANONICAL_TRUE];

  std::cout << "done" << std::endl;
}
示例#8
0
CString CSub::GetFileNameFromPath(CString path)
{
    CStringList words(10);
    Split("\\", m_NameOfFile, words);
    CString filename = words.GetAt(words.FindIndex(words.GetCount() - 1)) ;
    return filename;
}
示例#9
0
Ensure(Words, invokes_callback_for_each_word_in_a_phrase) {
    expect(mocked_callback, when(word, is_equal_to_string("Birds")));
    expect(mocked_callback, when(word, is_equal_to_string("of")));
    expect(mocked_callback, when(word, is_equal_to_string("a")));
    expect(mocked_callback, when(word, is_equal_to_string("feather")));
    words("Birds of a feather", &mocked_callback, NULL);
}
示例#10
0
size_t
UTF8StrChrFieldSearcher::matchTerms(const FieldRef & f, const size_t mintsz)
{
    (void) mintsz;
    termcount_t words(0);
    const byte * n = reinterpret_cast<const byte *> (f.data());
    const byte * e = n + f.size();
    if (f.size() >= _buf->size()) {
        _buf->reserve(f.size() + 1);
    }
    cmptype_t * fn = &(*_buf.get())[0];
    size_t fl(0);

    for( ; n < e; ) {
        if (!*n) { _zeroCount++; n++; }
        n = tokenize(n, _buf->capacity(), fn, fl);
        for(QueryTermList::iterator it=_qtl.begin(), mt=_qtl.end(); it != mt; it++) {
            QueryTerm & qt = **it;
            const cmptype_t * term;
            termsize_t tsz = qt.term(term);
            if ((tsz <= fl) && (prefix() || qt.isPrefix() || (tsz == fl))) {
                const cmptype_t *tt=term, *et=term+tsz;
                for (const cmptype_t *fnt=fn; (tt < et) && (*tt == *fnt); tt++, fnt++);
                if (tt == et) {
                    addHit(qt, words);
                }
            }
        }
        words++;
    }
    NEED_CHAR_STAT(addAnyUtf8Field(f.size()));
    return words;
}
std::set<std::string> chooseWords(std::string secret)
{
	// Initialise word list
	WordList words(wordLength);

	// Create a set to hold the list of options
	std::set<std::string> options;

	// Put the secret word in the set
	options.insert(secret);

	int likeWords = 0;
	while (options.size() < numberOfWords)
	{
		std::string word = words.getRandomWord();

		// Ensure that the minimum number of words are like
		if (likeWords < guaranteedNumberOfLikeWords)
		{
			int likeness = checkLikeness(word, secret);

			// They are like if more than half of the letters match the secret
			if (likeness > wordLength / 2)
			{
				options.insert(word);
				likeWords++;
			}

		}
		else
			options.insert(word);
	}

	return options;
}
示例#12
0
void listElements::tableInsert(unordered_map<string, vector<size_t>>& uMAP, const string& str, size_t idx)
{
	vector<string> words(1, str);
	string diver = " /-";
	for (size_t i = 0, j, pivot = 0; i <= str.size(); i++)
	{
		if (i == str.size())
		{
			words.push_back(str.substr(pivot, i - pivot));
			break;
		}
		for (j = 0; j < diver.size(); j++)
			if (str[i] == diver[j])
				break;
		if (j - diver.size())
		{
			words.push_back(str.substr(pivot, i - pivot));
			pivot = i + 1;
			i++;
		}
	}
	std::sort(words.begin(), words.end());
	words.erase(unique(words.begin(), words.end()), words.end());
	for (string s : words)
		for (size_t i = 1, j; i <= s.size(); i++)
		{
			for (j = 0; j < diver.size(); j++)
				if (s[i - 1] == diver[j])
					break;
			if (j == diver.size())
				tableInsertString(uMAP, s.substr(0, i), idx);
		}
}
示例#13
0
void main()
{
clrscr();
int choice;
char ch;
do{clrscr();
cout<<"\n MENU ";
cout<<"\n 1.CREATE";
cout<<"\n 2.DISPLAY";
cout<<"\n 3.NO OF UPPER CASE CHARACTERS ";
cout<<"\n 4.NO OF VOWELS";
cout<<"\n 5.NO OF DIGITS";
cout<<"\n 6.NO OF WORDS";
cout<<"\n 7.NUMBER OF LINES";
cout<<"\n enter ur choice";
cin>>choice;
switch(choice)
{
case 1:create();break;
case 2:display();break;
case 3:uppercase();break;
case 4:vowels();break;
case 5:digits();break;
case 6:words();break;
case 7:lines();break;
default: cout<<"\n wrong choice entered..!!";
}
cout<<"\n do you want to continue...??";
cin>>ch;
}
while(ch=='y'||ch=='Y');
}
示例#14
0
/* Allocates memory */
void factor_vm::set_profiling(bool profiling)
{
	if(profiling == profiling_p)
		return;

	profiling_p = profiling;

	/* Push everything to tenured space so that we can heap scan
	and allocate profiling blocks if necessary */
	gc();

	gc_root<array> words(find_all_words(),this);

	cell i;
	cell length = array_capacity(words.untagged());
	for(i = 0; i < length; i++)
	{
		tagged<word> word(array_nth(words.untagged(),i));
		if(profiling)
			word->counter = tag_fixnum(0);
		update_word_xt(word.value());
	}

	update_code_heap_words();
}
示例#15
0
vector<vector<DisambiguatedData> > Disambiguator::Disambiguate(
    const vector<Token>& tokens, double percentage, size_t maxNumberOfPaths
    , vector<double>* hypothesisDistribution)
{
    vector<PredisambiguatedData> predisambiguated
        = featureCalculator->CalculateFeatures(tokens);
    // Create chain
    size_t size = predisambiguated.size();
    vector<wstring> words(size);
    vector<vector<wstring> > features(size);
    vector<wstring> labels(size);
    for (size_t chainIndex = 0; chainIndex < size; ++chainIndex)
    {
        words[chainIndex] = predisambiguated[chainIndex].content;
        features[chainIndex] = predisambiguated[chainIndex].features;
    }
    LinearCRF::Chain chain(
        std::move(words)
        , std::move(features)
        , std::move(labels)
        , vector<vector<wstring> >());

    vector<vector<wstring> > bestSequences;
    vector<vector<double> > bestSequenceWeights;
    this->Apply(chain
                , percentage
                , maxNumberOfPaths
                , &bestSequences
                , &bestSequenceWeights
                , hypothesisDistribution);

    vector<vector<DisambiguatedData> > topDisambiguatedSequences;
    for (size_t chainIndex = 0; chainIndex < bestSequences.size()
            ; ++chainIndex)
    {
        vector<DisambiguatedData> disambiguatedData;
        for (size_t tokenIndex = 0; tokenIndex < size; ++tokenIndex)
        {
            wstring& label = bestSequences[chainIndex][tokenIndex];
            shared_ptr<Morphology> grammInfo = getBestGrammInfo(
                                                   predisambiguated[tokenIndex], label);
            applyPostprocessRules(&label, grammInfo);
            const wstring& lemma
                = dictionary == 0 ? DICT_IS_NULL
                  : *(grammInfo->lemma) == NOT_FOUND_LEMMA
                  ? Tools::ToLower(predisambiguated[tokenIndex].content) : *(grammInfo->lemma);
            disambiguatedData.emplace_back(
                predisambiguated[tokenIndex].content
                , predisambiguated[tokenIndex].punctuation
                , predisambiguated[tokenIndex].source
                , predisambiguated[tokenIndex].isNextSpace
                , lemma
                , label
                , bestSequenceWeights[chainIndex][tokenIndex]
                , grammInfo->lemma_id);
        }
        topDisambiguatedSequences.push_back(std::move(disambiguatedData));
    }
    return topDisambiguatedSequences;
}
示例#16
0
bool mpfx_manager::is_int(mpfx const & n) const {
    unsigned * w = words(n);
    for (unsigned i = 0; i < m_frac_part_sz; i++)
        if (w[i] != 0)
            return false;
    return true;
}
示例#17
0
void mpfx_manager::allocate(mpfx & n) {
    SASSERT(n.m_sig_idx == 0);
    unsigned sig_idx = m_id_gen.mk();
    ensure_capacity(sig_idx);
    n.m_sig_idx = sig_idx;
    SASSERT(::is_zero(m_total_sz, words(n)));
}
示例#18
0
void mpfx_manager::set_core(mpfx & n, mpq_manager<SYNCH> & m, mpq const & v) {
    if (m.is_int(v)) {
        set_core(n, m, v.numerator());
    }
    else {
        allocate_if_needed(n);
        _scoped_numeral<mpz_manager<SYNCH> > tmp(m);
        n.m_sign = is_neg(n);
        m.mul2k(v.numerator(), 8 * sizeof(unsigned) * m_frac_part_sz, tmp);
        m.abs(tmp);
        if ((n.m_sign == 1) != m_to_plus_inf && !m.divides(v.denominator(), tmp)) {
            m.div(tmp, v.denominator(), tmp);
            m.inc(tmp);
        }
        else {
            m.div(tmp, v.denominator(), tmp);
        }
        m_tmp_digits.reset();
        m.decompose(tmp, m_tmp_digits);
        unsigned sz = m_tmp_digits.size();
        if (sz > m_total_sz)
            throw overflow_exception();
        unsigned * w = words(n);
        ::copy(sz, m_tmp_digits.c_ptr(), m_total_sz, w);
    }
    SASSERT(check(n));
}
示例#19
0
void mpfx_manager::set(mpfx & n, uint64 v) {
    if (m_int_part_sz == 1) {
        if (v > static_cast<uint64>(UINT_MAX))
            throw overflow_exception();
    }

    if (v == 0) {
        reset(n);
    }
    else {
        allocate_if_needed(n);
        n.m_sign              = 0;
        unsigned * _v         = reinterpret_cast<unsigned*>(&v);
        unsigned * w          = words(n);
        for (unsigned i = 0; i < m_total_sz; i++) 
            w[i] = 0;
        w[m_frac_part_sz]     = _v[0];
        if (m_int_part_sz == 1) {
            SASSERT(_v[1] == 0);
        }
        else {
            w[m_frac_part_sz+1] = _v[1];
        }
    }
    SASSERT(is_int(n));
    SASSERT(get_uint64(n) == v);
    SASSERT(check(n));
}
示例#20
0
文件: pwords.c 项目: GarritMan/hw2
void* worker_thread(void* arg){
	thread_data *TData;
	TData=(thread_data *) arg;
	
	TData->dict=words(TData);
	pthread_exit(NULL);
}
QString
QvisSessionSourceChangerDialog::SplitPrompt(const QString &s) const
{
    static const int MAX_PROMPT_LENGTH = 60;
    if(s.length() < MAX_PROMPT_LENGTH)
        return s;
    else
    {
        stringVector words(SplitValues(std::string(s.toStdString()), ' '));
        QString r;
        size_t len = 0;
        for(size_t i = 0; i < words.size(); ++i)
        {
            if(len > 0)
                r += " ";
            r += QString(words[i].c_str());
            len += words[i].size();
            if(len >= (size_t)MAX_PROMPT_LENGTH)
            {
                r += "\n";
                len = 0;
            }
        }
        return r;
    }
}
示例#22
0
 vector<vector<string> > findLadders(string start, string end, curset &dict) {
   init(dict);
   
   vector<string> words(dict.begin(), dict.end());
   for (unsigned int i = 0; i < words.size(); i ++) wordsMap[words[i]] = i;
   
   for (int i = 0; i < words.size(); i ++) {
     string currWord = words[i];
     for (int j = 0; j < words[i].length(); j ++) {
       for (char k = 'a'; k <= 'z'; k ++) {
         if (words[i][j] == k) continue;
         
         currWord[j] = k;
         if (dict.find(currWord) != dict.end()) linkedList[i].push_back(wordsMap[currWord]);
       }
       currWord[j] = words[i][j];
     }
   }
   
   int offset = bfs(wordsMap[start], wordsMap[end]);
   if (offset == INT32_MAX) return ans;
   
   path.resize(offset + 1);
   dfs(offset, wordsMap[end], wordsMap[start]);
   
   for (int i = 0; i < ansPath.size(); i ++) {
     vector<string> p;
     for (int j = 0; j < ansPath[i].size(); j ++) {
       p.push_back(words[ansPath[i][j]]);
     }
     ans.push_back(p);
   }
   
   return ans;
 }
示例#23
0
double InputEvent::trueWordsPerMinute() const
{
  if(!m_processed)
    return 0;
  if(m_numWords == 0)
    words();
  return (double)m_numWords/m_counts.totalTime*60000;
}
 void reverseWords(string &s) {
     istringstream words(s);
     string word, res;
     while(words >> word)
         res = word + " " + res;
     if(!res.empty()) res.pop_back();
     s = res;
 }
示例#25
0
double parser_hyperbole::getB()
{

    double result2 = 3;


    char chars[] = "()";

    for (unsigned int i = 0; i < strlen(chars); ++i)
    {

        result.erase (std::remove(result.begin(), result.end(), chars[i]), result.end());
    }




    tokenizer words(result, " "); //the delimiters are space and = and ;


    list<string> lista;

    while(words.has_next())  //loop till we run out of items in deque
    {

        string s = words.next_token();

        lista.push_back(s);

    }

    list<string>::iterator i = lista.begin();


    std::advance(i, 2);

    std::string b = *i;

    if (b == "y^2"){
    b = "1";
    }

else{
  b =   b.substr(4,b.length()-4);
}

            double af = atof(b.c_str());
            result2 =  sqrt (af);





    return result2;



}
const HashSet<String> RussianAnalyzer::getDefaultStopSet() {
    static HashSet<String> stopSet;
    if (!stopSet) {
        String stopWords(UTF8_TO_STRING(DEFAULT_STOPWORD_FILE));
        Collection<String> words(StringUtils::split(stopWords, L"\n"));
        stopSet = HashSet<String>::newInstance(words.begin(), words.end());
    }
    return stopSet;
}
示例#27
0
void mpfx_manager::del(mpfx & n) {
    unsigned sig_idx = n.m_sig_idx;
    if (sig_idx != 0) {
        m_id_gen.recycle(sig_idx);
        unsigned * w = words(n);
        for (unsigned i = 0; i < m_total_sz; i++)
            w[i] = 0;
    }
}
示例#28
0
/**
 * Constructor of the AddGroupWindow class, generating its window.
 * @param	favorites	List of favorites tags, needed for coloration
 * @param	parent		The parent window
 */
AddGroupWindow::AddGroupWindow(QString selected, QStringList sites, QStringList favorites, QWidget *parent) : QWidget(parent), m_sites(sites)
{
	QVBoxLayout *layout = new QVBoxLayout;
		QFormLayout *formLayout = new QFormLayout;
			m_comboSites = new QComboBox;
				m_comboSites->setMaxVisibleItems(20);
				m_comboSites->addItems(m_sites);
				m_comboSites->setCurrentIndex(m_sites.indexOf(selected));
				formLayout->addRow(tr("&Site"), m_comboSites);
			m_lineTags = new TextEdit(favorites, this);
				m_lineTags->setContextMenuPolicy(Qt::CustomContextMenu);
				QStringList completion;
					QFile words("words.txt");
					if (words.open(QIODevice::ReadOnly | QIODevice::Text))
					{
						while (!words.atEnd())
						{
							QByteArray line = words.readLine();
							completion.append(QString(line).remove("\r\n").remove("\n").split(" ", QString::SkipEmptyParts));
						}
						QCompleter *completer = new QCompleter(completion, this);
						completer->setCaseSensitivity(Qt::CaseInsensitive);
						m_lineTags->setCompleter(completer);
					}
				formLayout->addRow(tr("&Tags"), m_lineTags);
			m_spinPage = new QSpinBox;
				m_spinPage->setRange(1, 1000);
				m_spinPage->setValue(1);
				formLayout->addRow(tr("&Page"), m_spinPage);
			m_spinPP = new QSpinBox;
				m_spinPP->setRange(1, 1000);
				m_spinPP->setValue(1000);
				formLayout->addRow(tr("&Images par page"), m_spinPP);
			m_spinLimit = new QSpinBox;
				m_spinLimit->setRange(1, 1000000);
				m_spinLimit->setValue(1000);
				formLayout->addRow(tr("&Limite d'images"), m_spinLimit);
			m_comboDwl = new QComboBox;
				m_comboDwl->setMaxVisibleItems(20);
				m_comboDwl->addItems(QStringList() << tr("Oui") << tr("Non"));
				m_comboDwl->setCurrentIndex(1);
				formLayout->addRow(tr("&Télécharger les image de la liste noire"), m_comboDwl);
			layout->addLayout(formLayout);
		QHBoxLayout *layoutButtons = new QHBoxLayout;
			QPushButton *buttonOk = new QPushButton(tr("Ok"));
				connect(buttonOk, SIGNAL(clicked()), this, SLOT(ok()));
				layoutButtons->addWidget(buttonOk);
			QPushButton *buttonClose = new QPushButton(tr("Fermer"));
				connect(buttonClose, SIGNAL(clicked()), this, SLOT(close()));
				layoutButtons->addWidget(buttonClose);
			layout->addLayout(layoutButtons);
	this->setLayout(layout);
	this->setWindowIcon(QIcon(":/images/icon.ico"));
	this->setWindowTitle(tr("Ajouter groupe"));
	this->setWindowFlags(Qt::Window);
	this->resize(QSize(400, 0));
}
示例#29
0
文件: time.cpp 项目: marccodes/lfl
bool NumericTime(const char *text, int *hour, int *min, int *sec) {
    int textlen = strlen(text);
    StringWordIter words(StringPiece(text, textlen), isint<':'>);
    *hour = atoi(IterNextString(&words));
    *min = atoi(IterNextString(&words));
    *sec = atoi(IterNextString(&words));
    if (textlen >= 2 && !strcmp(text+textlen-2, "pm") && *hour != 12) *hour += 12;
    return true;
}
示例#30
0
void SplitTest2()
{
	std::string s = "Hello my baby!";
	std::istringstream iss(s);
	std::istream_iterator<std::string> beg(iss), end;
	std::vector<std::string> words(beg, end);
	for(auto & w : words)
		std::cout << w << std::endl;
}