Esempio n. 1
0
bool TagType::contains(Term &t)
{
  if (!t.is_tagged_obj())
    return false;
  Term tag_obj = symbol_obj(t.get_tag());
  return tag_type->contains(tag_obj) && obj_type->contains(t.untag());
}
Esempio n. 2
0
void initial()
{
	if((int)str_signature_file.length() > 0)
		gapped_dipeptide_term.initial(str_signature_file);
	else
		gapped_dipeptide_term.initial(param.gapped_distance);
}
QMimeData *TableModelVariables::mimeData(const QModelIndexList &indexes) const
{
	QMimeData *mimeData = new QMimeData();
	QByteArray encodedData;

	QDataStream dataStream(&encodedData, QIODevice::WriteOnly);

	dataStream << indexes.length();

	foreach (const QModelIndex &index, indexes)
	{
		if (index.isValid())
		{
			Term term = _variables.at(index.row());
			dataStream << term.asQString();
		}
	}

	TableModelVariables* th1s = (TableModelVariables*) this;
	th1s->_mimeData = mimeData;

	mimeData->setData(_mimeType, encodedData);

	return mimeData;
}
Esempio n. 4
0
void block_update_state_type(Block* block)
{
    if (!block_state_type_is_out_of_date(block))
        return;

    // Recreate the state type
    Type* type = create_compound_type();

    // TODO: give this new type a nice name

    for (int i=0; i < block->length(); i++) {
        Term* term = block->get(i);
        if (term == NULL)
            continue;

        if (term->function != FUNCS.unpack_state || FUNCS.unpack_state == NULL)
            continue;

        Term* identifyingTerm = term->input(1);

        caValue* fieldName = get_unique_name(identifyingTerm);
        ca_assert(is_string(fieldName));
        ca_assert(!string_eq(fieldName, ""));

        compound_type_append_field(type, declared_type(term), as_cstring(fieldName));
    }

    block->stateType = type;
    block_remove_property(block, sym_DirtyStateType);

    // Might need to update any existing pack_state calls.
    block_update_pack_state_calls(block);
}
void bug_reproducing_list_after_eval()
{
    // There once was a bug where source repro would fail when using a list
    // in a vectorized function, but only after that piece of code had been
    // evaluated. This was because vectorize_vv was calling apply() which
    // was changing the 'statement' property of its inputs.
    Branch branch;

    Term* sum = branch.compile("[1 1] + [1 1]");
    Term* in0 = sum->input(0);
    Term* in1 = sum->input(0);

    test_equals(get_term_source_text(in0), "[1 1]");
    test_equals(get_term_source_text(in1), "[1 1]");
    test_equals(get_input_source_text(sum, 0), "[1 1] ");
    test_equals(get_input_source_text(sum, 1), " [1 1]");
    test_equals(get_branch_source_text(&branch), "[1 1] + [1 1]");

    evaluate_branch(&branch);

    test_equals(get_term_source_text(in0), "[1 1]");
    test_equals(get_term_source_text(in1), "[1 1]");
    test_equals(get_input_source_text(sum, 0), "[1 1] ");
    test_equals(get_input_source_text(sum, 1), " [1 1]");

    test_equals(get_branch_source_text(&branch), "[1 1] + [1 1]");
}
Esempio n. 6
0
/**
 * find matching terms.
 * @param inQuery the term with a wildcard for which the matching terms should be found.
 * @param 
 *
 */
void LuceneSearcher::findMatchingTerms(string inTerm, map<string, int> &ioTerms){

  if (mLuceneSearcher == 0){

    openIndex();
  }
  set<string> matchingTerms;
  TCHAR buffer[200];
  char buffer2[200];
  STRCPY_AtoT(buffer, inTerm.c_str(), 200);   
  Term *theTerm = new Term(_T("content"), buffer, false);
  lucene::analysis::Analyzer *theAnalyzer = 
    new lucene::analysis::standard::StandardAnalyzer();
  set<string>::iterator iter;
  STRCPY_TtoA(buffer2, theTerm->text(), 200);
  //cerr << "findMatchingTerms for the words: " << buffer2 << endl;
  //cerr << "findMatchingTerms getReader is " << mLuceneSearcher->getReader() << endl;
  //cerr << "getDirectgory is " << mLuceneSearcher->getReader()->getDirectory() << endl;
  TermEnum *tEnum = mLuceneSearcher->getReader()->terms();
  //cerr << "Termenum is " << tEnum << endl;
  //cerr << "numdocs is " << mLuceneSearcher->getReader()->numDocs() << endl;


  WildcardTermEnum termEnum(mLuceneSearcher->getReader(), theTerm); 
  //cerr << "Wildcardenum succeeded" << endl;
  while(termEnum.next()){
       
    Term *term = termEnum.term(false);
    STRCPY_TtoA(buffer2, term->text(), 200);
    //cerr << "adding term " << term->text() << endl;
    ioTerms[string(buffer2)] += termEnum.docFreq();
    } 
  //cerr << "done findMatchingTerms" << endl; 
  _CLDECDELETE(theTerm);
}
Esempio n. 7
0
main()
{
Polynomial p;
Polynomial *q = new Polynomial;

Term e;
cout << "start" << endl;
e.Init(3, 14); p.Add(e);
e.Init(2,8); p.Add(e);
e.Init(1,0); p.Add(e);
cout << "p" << endl << p << endl;

e.Init(-3,13) ; q->Add(e);
e.Init(-2,8); q->Add(e);
e.Init(-1,1) ; q->Add(e);

cout << "q" << endl << *q << endl;

Polynomial r = p + *q;
cout << "r = p + q" << endl << r << endl;



Polynomial s;
cout << "s" << endl << s << endl;

Polynomial t = s + s;
cout << "t = s + s" << endl << t << endl;

Polynomial u = p + p;
cout << "u = p + p" << endl << u << endl;
}
Esempio n. 8
0
bool Multivector::CollectTerms( Term::ProductType productType )
{
	Term::ProductType otherProductType = Term::OtherProductType( productType );

	for(;;)
	{
		SumOfTerms::Node* node = FindTermOfProductType( otherProductType );
		if( !node )
			break;

		Term* term = node->data;

		Multivector multivector;
		if( !term->PerformProductMorphism( multivector ) )
			return false;

		sumOfTerms.Remove( node, true );
		sumOfTerms.Absorb( &multivector.sumOfTerms );
	}

	if( productType == Term::OUTER_PRODUCT )
	{
		// STPTODO: Presort all term products, accounting for the sign change.  This way we can use CombineWidth( ..., false ) to save time.
	}

	// STPTODO: Combine terms here.

	// STPTODO: Cull zero terms here.

	return true;
}
Esempio n. 9
0
static void append_final_pack_state(Branch* branch)
{
    TermList inputs;
    get_list_of_state_outputs(branch, branch->length(), &inputs);
    Term* term = apply(branch, FUNCS.pack_state, inputs);
    term->setBoolProp("final", true);
}
Esempio n. 10
0
void start_building_for_loop(Block* contents, Term* listExpr, Value* indexName,
    Value* elementName, Type* iteratorType)
{
    Term* iterator = apply(contents, FUNCS.loop_iterator, TermList(listExpr));

    Term* done = apply_dynamic_method(contents, s_done, TermList(iterator));
    hide_from_source(done);

    Term* getKey = apply_dynamic_method(contents, s_key, TermList(iterator));
    hide_from_source(getKey);

    if (!is_null(indexName)) {
        Term* getIndex = apply_dynamic_method(contents, s_key, TermList(iterator), indexName);
        hide_from_source(getIndex);
    }

    Term* getCurrent = apply_dynamic_method(contents, s_current, TermList(iterator), elementName);
    getCurrent->setBoolProp(s_iterator_value, true);
    hide_from_source(getCurrent);

    if (iteratorType != NULL) {
        Term* castedValue = apply(contents, FUNCS.cast,
            TermList(getCurrent, iteratorType->declaringTerm), elementName);
    }
}
Esempio n. 11
0
Term* loop_find_condition(Block* block)
{
    Term* conditionCheck = loop_find_condition_check(block);
    if (conditionCheck != NULL)
        return conditionCheck->input(0);
    return NULL;
}
Esempio n. 12
0
Term* TermEnum::term(bool pointer)
{
	Term* ret = term();
	if (!pointer)
		ret->__cl_decref();
	return ret;
}
Esempio n. 13
0
void finish_for_loop(Term* forTerm)
{
    Branch* contents = nested_contents(forTerm);

    // Need to finish here to prevent error
    branch_finish_changes(contents);

    // Add a a primary output
    Term* primaryOutput = apply(contents, FUNCS.output,
            TermList(loop_get_primary_result(contents)));
    primaryOutput->setBoolProp("accumulatingOutput", true);
    respecialize_type(primaryOutput);

    // pack_any_open_state_vars(contents);
    for_loop_fix_state_input(contents);
    check_to_add_state_output_placeholder(contents);

    add_implicit_placeholders(forTerm);
    repoint_terms_to_use_input_placeholders(contents);

    check_to_insert_implicit_inputs(forTerm);
    update_extra_outputs(forTerm);

    branch_finish_changes(contents);
}
Esempio n. 14
0
bool Enum::contains(Term &t)
{
  if (!t.is_symbol())
    return false;

  return in_sorted_vector(t.get_symbol(), symbols);
}
Esempio n. 15
0
Term* ArithmeticTerm::canonicalize(ArithmeticTerm* at)
{
	if(at->get_elems().size() == 0) {
		long int constant = at->get_constant();
		delete at;
		return ConstantTerm::make(constant);
	}
	if(at->get_constant() == 0 && at->get_elems().size() == 1 &&
			(at->get_elems().begin())->second ==1)
	{
		Term* t = at->get_elems().begin()->first;
		switch(t->get_term_type())
		{
		case VARIABLE_TERM:
		case FUNCTION_TERM:
		{
			delete at;
			return t;
		}
		default:
			assert(false);
		}
	}

	return Term::get_term(at);
}
Esempio n. 16
0
void repoint_terms_to_use_input_placeholders(Branch* contents)
{
    // Visit every term
    for (int i=0; i < contents->length(); i++) {
        Term* term = contents->get(i);

        // Visit every input
        for (int inputIndex=0; inputIndex < term->numInputs(); inputIndex++) {
            Term* input = term->input(inputIndex);
            if (input == NULL)
                continue;
            
            // If the input is outside this branch, then see if we have a named
            // input that could be used instead.
            if (input->owningBranch == contents || input->name == "")
                continue;

            Term* replacement = find_input_placeholder_with_name(contents, input->name.c_str());
            if (replacement == NULL)
                continue;

            set_input(term, inputIndex, replacement);
        }
    }
}
Esempio n. 17
0
void Term__num_inputs(VM* vm)
{
    Term* t = as_term_ref(vm->input(0));
    if (t == NULL)
        return vm->throw_str("NULL term");
    set_int(vm->output(), t->numInputs());
}
Esempio n. 18
0
//////////////////////////////////////
// initialize matching terms iterator
//
int DbIntlog::Search(Term t, DbEntryIter &iter, DbIntlog *dbs)
{
#ifdef _DEBUG
    CCP tstring = t.get_funct();
#endif

    DbEntry e = DbEntry(t.get_funct(), t.get_arity()),
            *dbe = isin(e);

    if (!dbe)
    {
        if (dbs == 0 ||
                (dbe = dbs->isin(e)) == 0 ||
                dbe->vProp != DbEntry::dynamic)
        {
            iter.pcc = 0;
            iter.own = iter.mod = 0;
            return 0;
        }
        iter.mod =
		iter.own = dbs;
    }
    else
    {
        iter.mod = this;
        iter.own = dbs;
    }

    // initialize for later search
    iter.pcc = (e_DbList*)dbe->get_first()->fix_clause(dbs);
    iter.pcp = 0;

    return 1;
}
Esempio n. 19
0
fixed
ServiceCharges::balanceOn(const Gltx& gltx, QDate date)
{
    QDate dueDate = gltx.postDate();
    if (gltx.dataType() == DataObject::INVOICE) {
	Id term_id = invoiceTermId(gltx.id());
	if (term_id != INVALID_ID) {
	    Term term;
	    if (findTerm(term_id, term))
		dueDate = gltx.postDate() + term.dueDays();
	}
    }
    if (date < dueDate) return 0.0;

    fixed balance = gltx.cardTotal();
    for (unsigned int i = 0; i < gltx.payments().size(); ++i) {
	Id payment_id = gltx.payments()[i].gltx_id;
	fixed amount = gltx.payments()[i].amount;
	Gltx payment;
	if (!findGltx(payment_id, payment))
	    continue;
	if (payment.postDate() <= date)
	    balance -= amount;
    }

    return balance;
}
Esempio n. 20
0
///////////////////////////////////////
// on qualified name, select direct DB
//
DbIntlog *DbIntlog::FixPathName(Term *t) const
{
    DbIntlog *db = (DbIntlog*)this;
    Term r = *t;

    while (db && r.is_expr(Operator::PATHNAME) && r.getarg(0).type(f_ATOM))
    {
        kstring dbid = r.getarg(0).kstr();

        if (!strcmp(dbid, ".."))
            db = db->m_father;
        else
        {
            DbInherIter itdb(db);
            while ((db = itdb.next()) != 0)
                if (db->GetId() == dbid)
                    break;
        }

        if (db)
            r = r.getarg(1);
    }

    *t = r;
    return db;
}
Esempio n. 21
0
File: iafx.cpp Progetto: CapelliC/IL
/////////////////////////////////////////////////////////////////
// attempt a parse and call
//	if query succeed, copy vars values to v[] (up to nv elements)
//	you must guarantee that nv >= 'num of vars in src'
//
IIFTYPE(int) IAFX_QueryString(const char *src, EngHandle h, Term **var_val, kstr_list *var_ids)
{
	int rc = -1;	// if some error occurs
	IntlogExec *ile = GetEngines()->HtoD(h);

	if (ile != 0)
	{
		// prepare input source stream
		IntlogParser* parser = GetEngines()->get_parser();
        istringstream srcstream(src);

		// save status
		parser->SetSource(&srcstream, "QueryString", var_ids);

		// submit source line: if parse ok, query
		if (parser->getinput() == IntlogParser::NewClause)
		{
			Term tparsed = parser->parsed;

			int nv = var_ids->numel();
			if (nv > 0)
				*var_val = new Term[nv];

			rc = runquery(ile, tparsed, var_ids, *var_val, var_ids->numel());

			tparsed.Destroy();
		}
	}

	// some error occurred
	return rc;
}
Esempio n. 22
0
    Term* FllImporter::parseTerm(const std::string& text, Engine* engine) const {
        std::vector<std::string> tokens = Op::split(text, " ");

        //MEDIUM Triangle 0.500 1.000 1.500

        if (tokens.size() < 2) {
            throw fl::Exception("[syntax error] expected a term in format <name class parameters>, "
                    "but found <" + text + ">", FL_AT);
        }
        Term* term = FactoryManager::instance()->term()->createInstance(tokens.at(1));
        term->setName(Op::makeValidId(tokens.at(0)));
        std::ostringstream parameters;
        for (std::size_t i = 2; i < tokens.size(); ++i) {
            parameters << tokens.at(i);
            if (i + 1 < tokens.size()) parameters << " ";
        }
        term->configure(parameters.str());
        //special cases:
        Linear* linear = NULL;
        Function* function = NULL;
        if ((linear = dynamic_cast<Linear*> (term))) {
            linear->inputVariables = std::vector<const InputVariable*>
                    (engine->inputVariables().begin(),
                    engine->inputVariables().end());
        } else if ((function = dynamic_cast<Function*> (term))) {
            function->setEngine(engine);
            //builtin functions are loaded from TermFactory calling Function::create
            function->load();
        }
        return term;
    }
Esempio n. 23
0
void BlockInputIterator::advanceWhileInvalid()
{
possibly_invalid:

    if (finished())
        return;

    Term* current = blockIterator.current();

    if (current == NULL) {
        blockIterator.advance();
        inputIndex = 0;
        goto possibly_invalid;
    }

    if (inputIndex >= current->numInputs()) {
        blockIterator.advance();
        inputIndex = 0;
        goto possibly_invalid;
    }

    if (current->input(inputIndex) == NULL) {
        inputIndex++;
        goto possibly_invalid;
    }
}
Esempio n. 24
0
void migrate_block(Block* target, Migration* migration)
{
    ca_assert(target != migration->oldBlock);

    if (target == migration->newBlock)
        return;

    // Store a cache of lookups that we've made in this call.
    TermMap cache;

    for (BlockIterator it(target); it; ++it) {

        Term* term = *it;

        // Iterate through each "dependency", which includes the function & inputs.
        for (int i=0; i < term->numDependencies(); i++) {
            Term* ref = term->dependency(i);
            Term* newRef = NULL;

            if (cache.contains(ref)) {
                newRef = cache[ref];
            } else {

                // Lookup and save result in cache
                newRef = migrate_term_pointer(ref, migration);
                cache[ref] = newRef;
            }

            // Possibly rebind
            if (newRef != ref)
                term->setDependency(i, newRef);
        }
    }
}
Esempio n. 25
0
bool term_is_observable_after(Term* term, Term* location)
{
    // Check if "term" can be observed after the "location".
    //
    // Typically, "location" uses "term" as an input, and we're trying to decide
    // whether the call at "location" can move/consume the value.

    if (term_is_observable_for_special_reasons(term))
        return true;

    for (int i=0; i < user_count(term); i++) {
        Term* user = term_user(term, i);

        if (user->function == FUNCS.upvalue)
            return true;

        if (terms_are_in_different_switch_conditions(location, user))
            continue;

        if (term_accesses_input_from_inside_loop(user, term)) {

            bool userOnlyAccessesOnFirstIteration = is_input_placeholder(user)
                && user->numInputs() == 2
                && user->input(1) != term;

            if (!userOnlyAccessesOnFirstIteration)
                return true;
        }

        if (is_located_after(user, location))
            return true;
    }
 
    return false;
}
Esempio n. 26
0
void dynamic_method_call(caStack* stack)
{
    INCREMENT_STAT(DynamicMethodCall);

    caValue* args = circa_input(stack, 0);
    caValue* object = circa_index(args, 0);

    // Lookup method
    Term* term = (Term*) circa_caller_term(stack);
    std::string functionName = term->stringProp("syntax:functionName", "");

    // Find and dispatch method
    Term* method = find_method((Block*) circa_caller_block(stack),
        (Type*) circa_type_of(object), functionName.c_str());

    // copy(object, circa_output(stack, 1));

    if (method != NULL) {
        // Grab inputs before pop
        Value inputs;
        swap(args, &inputs);

        pop_frame(stack);
        push_frame_with_inputs(stack, function_contents(method), &inputs);
        return;
    }

    // Method not found. Raise error.
    std::string msg;
    msg += "Method ";
    msg += functionName;
    msg += " not found on type ";
    msg += as_cstring(&circa_type_of(object)->name);
    circa_output_error(stack, msg.c_str());
}
Esempio n. 27
0
void branch_update_state_type(Branch* branch)
{
    if (branch_state_type_is_out_of_date(branch)) {

        // TODO: Handle the case where the stateType should go from non-NULL to NULL

        // Recreate the state type
        Type* type = create_compound_type();

        // TODO: give this new type a nice name

        for (int i=0; i < branch->length(); i++) {
            Term* term = branch->get(i);
            if (term == NULL)
                continue;

            if (term->function != FUNCS.unpack_state || FUNCS.unpack_state == NULL)
                continue;

            Term* identifyingTerm = term->input(1);

            compound_type_append_field(type, declared_type(term), unique_name(identifyingTerm));
        }

        branch->stateType = type;

        // Might need to update any existing pack_state calls.
        branch_update_existing_pack_state_calls(branch);
    }
}
Esempio n. 28
0
QVariant AnalysisForm::requestInfo(const Term &term, VariableInfo::InfoType info) const
{
	try {

		if (info == VariableInfo::VariableType)
		{
			return _dataSet->column(term.asString()).columnType();
		}
		else if (info == VariableInfo::Labels)
		{
			QStringList values;
			Labels &labels = _dataSet->column(term.asString()).labels();
			for (Labels::const_iterator label_it = labels.begin(); label_it != labels.end(); ++label_it)
				values.append(tq(label_it->text()));

			return values;
		}
	}
	catch(columnNotFound e) {} //just return an empty QVariant right?
	catch(std::exception e)
	{
#ifdef JASP_DEBUG
		std::cout << "AnalysisForm::requestInfo had an exception! " << e.what() << std::flush;
#endif
		throw e;
	}
	return QVariant();

}
QVariant TableModelVariables::data(const QModelIndex &index, int role) const
{
	int row = index.row();

	if (role == Qt::DisplayRole)
	{
		Term term = _variables.at(row);
		return QVariant(term.asQString());
	}
	else if (role == Qt::DecorationRole)
	{
		Term term = _variables.at(row);
		int variableType = requestInfo(term, VariableInfo::VariableType).toInt();

		switch (variableType)
		{
		case Column::ColumnTypeNominalText:
			return QVariant(_nominalTextIcon);
		case Column::ColumnTypeNominal:
			return QVariant(_nominalIcon);
		case Column::ColumnTypeOrdinal:
			return QVariant(_ordinalIcon);
		case Column::ColumnTypeScale:
			return QVariant(_scaleIcon);
		default:
			return QVariant();
		}
	}
	else
	{
		return QVariant();
	}
}
Esempio n. 30
0
bool TupleType::contains(Term &t)
{
  if (!t.is_tuple() || t.size() < min_size)
    return false;
  
  int size = keys.size();
  int matched = 0;
  
  for (int i=0 ; i < size ; i++)
  {
    Term key = symbol_obj(keys[i]);
    
    if (t.has_key(key))
    {
      Term &value = t.lookup(key);
      if (!types[i]->contains(value))
        return false;
      matched++;
    }
    else
    {
      if (!optional[i])
        return false;
    }
  }
  
  return t.size() == matched;
}