Generate statements by expanding members of families and complexes.
493810
def expand_families(self, stmts):
        
        new_stmts = []
        for stmt in stmts:
            # Put together the lists of families, with their members. E.g.,
            # for a statement involving RAF and MEK, should return a list of
            # tuples like [(BRAF, RAF1, ARAF), (MAP2K1, MAP2K2)]
            families_list = []
            for ag in stmt.agent_list():
                ag_children = self.get_children(ag)
                # If the agent has no children, then we use the agent itself
                if len(ag_children) == 0:
                    families_list.append([ag])
                # Otherwise, we add the tuple of namespaces/IDs for the children
                else:
                    families_list.append(ag_children)
            # Now, put together new statements frmo the cross product of the
            # expanded family members
            for ag_combo in itertools.product(*families_list):
                # Create new agents based on the namespaces/IDs, with
                # appropriate name and db_refs entries
                child_agents = []
                for ag_entry in ag_combo:
                    # If we got an agent, or None, that means there were no
                    # children; so we use the original agent rather than
                    # construct a new agent
                    if ag_entry is None or isinstance(ag_entry, Agent):
                        new_agent = ag_entry
                    # Otherwise, create a new agent from the ns/ID
                    elif isinstance(ag_entry, tuple):
                        # FIXME FIXME FIXME
                        # This doesn't reproduce agent state from the original
                        # family-level statements!
                        ag_ns, ag_id = ag_entry
                        new_agent = _agent_from_ns_id(ag_ns, ag_id)
                    else:
                        raise Exception('Unrecognized agent entry type.')
                    # Add agent to our list of child agents
                    child_agents.append(new_agent)
                # Create a copy of the statement
                new_stmt = deepcopy(stmt)
                # Replace the agents in the statement with the newly-created
                # child agents
                new_stmt.set_agent_list(child_agents)
                # Add to list
                new_stmts.append(new_stmt)
        return new_stmts
1188695
def generate(self,**kwargs):
        """"""
        import collections
        all_params = cartesian_dicts({k:kwargs[k] for k in kwargs.keys() if isinstance(kwargs[k], collections.Iterable)})
        for pi,p in enumerate(all_params):
            if self.name_mode == 'int':
                n = str(len(self.containers))
            else:
                n = None
            self.containers.append(PDContainer(name=n,params=p,parent=self))
        self.parameters.update({ k: kwargs[k] for k in kwargs.keys() if not isinstance(kwargs[k], collections.Iterable) })
        self.save()
1123894
def create_many(self, statements):
        
        Statement = self.get_model('statement')
        Tag = self.get_model('tag')

        session = self.Session()

        create_statements = []
        create_tags = {}

        for statement in statements:

            statement_data = statement.serialize()
            tag_data = statement_data.pop('tags', [])

            statement_model_object = Statement(**statement_data)

            if not statement.search_text:
                statement_model_object.search_text = self.tagger.get_bigram_pair_string(statement.text)

            if not statement.search_in_response_to and statement.in_response_to:
                statement_model_object.search_in_response_to = self.tagger.get_bigram_pair_string(statement.in_response_to)

            new_tags = set(tag_data) - set(create_tags.keys())

            if new_tags:
                existing_tags = session.query(Tag).filter(
                    Tag.name.in_(new_tags)
                )

                for existing_tag in existing_tags:
                    create_tags[existing_tag.name] = existing_tag

            for tag_name in tag_data:
                if tag_name in create_tags:
                    tag = create_tags[tag_name]
                else:
                    # Create the tag if it does not exist
                    tag = Tag(name=tag_name)

                    create_tags[tag_name] = tag

                statement_model_object.tags.append(tag)
            create_statements.append(statement_model_object)

        session.add_all(create_statements)
        session.commit()
408012
def new_children(self, **kwargs):
        """"""
        for k, v in kwargs.items():
            self.new_child(k, v)

        return self
1268428
def expressions(self):
        
        for s in self.statements:
            for expr_ in s.expressions:
                yield expr_
        yield self.next
154044
def visit_statements(self, nodes):
    """"""
    primals, adjoints = [], collections.deque()
    for node in nodes:
      primal, adjoint = self.visit(node)
      if not isinstance(primal, list):
        primal = [primal]
      if not isinstance(adjoint, list):
        adjoint = [adjoint]
      # Methods will return `None` if the node is to be removed, so remove them
      primals.extend(filter(None, primal))
      # We reverse the order of the adjoints, but not the statements in
      # the adjoint itself
      adjoints.extendleft(filter(None, adjoint[::-1]))
    return primals, list(adjoints)
61784
private void expandAttributeNodes(CComplexObject sourceObject) {
        List<CAttribute> differentialAttributes = Lists.newArrayList();
        for (CAttribute cAttribute : sourceObject.getAttributes()) {
            if (cAttribute.getDifferentialPath() != null) {
                differentialAttributes.add(cAttribute);
            }

        }

        for (CAttribute specializedAttribute : differentialAttributes) {
            expandAttribute(sourceObject, specializedAttribute);
            sourceObject.getAttributes().remove(specializedAttribute);
        }

        for (CAttribute cAttribute : sourceObject.getAttributes()) {
            for (CObject cObject : cAttribute.getChildren()) {
                if (cObject instanceof CComplexObject) {
                    expandAttributeNodes((CComplexObject) cObject);
                }
            }
        }
    }
803028
def _rt_members_add(self, element, statement):
        """"""
        members = self.vparser.parse(statement, None)
        for member in members:
            single = members[member]
            single.parent = element
            element.members[member] = single
74834
def generate(size, output, schema):
    """"""
    pii_data = randomnames.NameList(size)

    if schema is not None:
        raise NotImplementedError

    randomnames.save_csv(
        pii_data.names,
        [f.identifier for f in pii_data.SCHEMA.fields],
        output)
478176
private void populateQueryComponents(EntityMetadata m, QueryComponent sq)
    {
        boolean hasChildren = false;
        if (sq.children != null && sq.children.size() > 0)
        {
            hasChildren = true;
            for (QueryComponent subQ : sq.children)
            {
                populateQueryComponents(m, subQ);
            }
        }
        if (sq.clauses.size() > 0 || hasChildren)
        {
            if (sq.clauses.size() > 0)
            {
                sq.actualQuery = createSubMongoQuery(m, sq.clauses);
            }
            if (hasChildren)
            {
                List<BasicDBObject> childQs = new ArrayList<BasicDBObject>();
                if (sq.clauses.size() > 0)
                    childQs.add(sq.actualQuery);
                for (QueryComponent subQ : sq.children)
                {
                    childQs.add(subQ.actualQuery);
                }
                if (childQs.size() == 1)
                {
                    sq.actualQuery = childQs.get(0);
                }
                else if (sq.isAnd)
                {
                    BasicDBObject dbo = new BasicDBObject("$and", childQs);
                    sq.actualQuery = dbo;
                }
                else
                {
                    BasicDBObject dbo = new BasicDBObject("$or", childQs);
                    sq.actualQuery = dbo;
                }
            }
        }
    }
1356172
def gen_parents(parents):
    """"""
    for idx, parent in enumerate(parents):
        if isinstance(parent, Interface):
            parent = parent.id
        elif isinstance(parent, int):
            pass
        else:
            raise TypeError(
                'parent[%d] must be an Interface or int, not %s' % (
                    idx, type(parent).__name__))
        yield parent
1102326
function expand (node, args, i) {
	var n = args.length;
	var arg;
	for (; i < n; i++) {
		arg = args [i];
		if (isNodeType (arg, types.MACRO)) {
			expand (node, arg, 1);

		} else {
			node.push (arg);
		}
	}
	return node;
}
59974
protected static Map<String, List<Statement>> addStatementToGroups(Statement statement, Map<String, List<Statement>> claims) {
		Map<String, List<Statement>> newGroups = new HashMap<>(claims);
		String pid = statement.getMainSnak().getPropertyId().getId();
		if(newGroups.containsKey(pid)) {
			List<Statement> newGroup = new ArrayList<>(newGroups.get(pid).size());
			boolean statementReplaced = false;
			for(Statement existingStatement : newGroups.get(pid)) {
				if(existingStatement.getStatementId().equals(statement.getStatementId()) &&
						!existingStatement.getStatementId().isEmpty()) {
					statementReplaced = true;
					newGroup.add(statement);
				} else {
					newGroup.add(existingStatement);
				}
			}
			if(!statementReplaced) {
				newGroup.add(statement);
			}
			newGroups.put(pid, newGroup);
		} else {
			newGroups.put(pid, Collections.singletonList(statement));
		}
		return newGroups;
	}
132294
def synthesize(self, modules, use_string, x64, native):
        """"""
        # code_opts = CodeOpts(
        #     str.lower, None if use_string else hash_func,
        #     'reloc_delta', '->',
        #     True)
        # gen_opts = GenOpts('defs', transformed)
        print(hash_func)
        groups = group_by(modules, ends_with_punctuation)
        sources = self.make_source(groups, self.database)
        if sources:
            return stylify_files(
                {'defs.h': sources[0], 'init.c': sources[1]}
            )
        else:
            return ''
12655
def extract_statements(self):
        """"""
        for _, (tf, target, effect, refs) in self.df.iterrows():
            tf_agent = get_grounded_agent(tf)
            target_agent = get_grounded_agent(target)
            if effect == 'Activation':
                stmt_cls = IncreaseAmount
            elif effect == 'Repression':
                stmt_cls = DecreaseAmount
            else:
                continue
            pmids = refs.split(';')
            for pmid in pmids:
                stmt = make_stmt(stmt_cls, tf_agent, target_agent, pmid)
                self.statements.append(stmt)
679487
protected void buildSQLStatements() {
        // prepare statements
        if (getStorageModel() == SM_BINARY_KEYS) {
            bundleInsertSQL = "insert into " + schemaObjectPrefix + "BUNDLE (BUNDLE_DATA, NODE_ID) values (?, ?)";
            bundleUpdateSQL = "update " + schemaObjectPrefix + "BUNDLE set BUNDLE_DATA = ? where NODE_ID = ?";
            bundleSelectSQL = "select BUNDLE_DATA from " + schemaObjectPrefix + "BUNDLE where NODE_ID = ?";
            bundleDeleteSQL = "delete from " + schemaObjectPrefix + "BUNDLE where NODE_ID = ?";

            nodeReferenceInsertSQL = "insert into " + schemaObjectPrefix + "REFS (REFS_DATA, NODE_ID) values (?, ?)";
            nodeReferenceUpdateSQL = "update " + schemaObjectPrefix + "REFS set REFS_DATA = ? where NODE_ID = ?";
            nodeReferenceSelectSQL = "select REFS_DATA from " + schemaObjectPrefix + "REFS where NODE_ID = ?";
            nodeReferenceDeleteSQL = "delete from " + schemaObjectPrefix + "REFS where NODE_ID = ?";

            bundleSelectAllIdsSQL = "select NODE_ID from " + schemaObjectPrefix + "BUNDLE ORDER BY NODE_ID";
            bundleSelectAllIdsFromSQL = "select NODE_ID from " + schemaObjectPrefix + "BUNDLE WHERE NODE_ID > ? ORDER BY NODE_ID";
            bundleSelectAllBundlesSQL = "select NODE_ID, BUNDLE_DATA from " + schemaObjectPrefix + "BUNDLE ORDER BY NODE_ID";
            bundleSelectAllBundlesFromSQL = "select NODE_ID, BUNDLE_DATA from " + schemaObjectPrefix + "BUNDLE WHERE NODE_ID > ? ORDER BY NODE_ID";
        } else {
            bundleInsertSQL = "insert into " + schemaObjectPrefix + "BUNDLE (BUNDLE_DATA, NODE_ID_HI, NODE_ID_LO) values (?, ?, ?)";
            bundleUpdateSQL = "update " + schemaObjectPrefix + "BUNDLE set BUNDLE_DATA = ? where NODE_ID_HI = ? and NODE_ID_LO = ?";
            bundleSelectSQL = "select BUNDLE_DATA from " + schemaObjectPrefix + "BUNDLE where NODE_ID_HI = ? and NODE_ID_LO = ?";
            bundleDeleteSQL = "delete from " + schemaObjectPrefix + "BUNDLE where NODE_ID_HI = ? and NODE_ID_LO = ?";

            nodeReferenceInsertSQL =
                "insert into " + schemaObjectPrefix + "REFS"
                + " (REFS_DATA, NODE_ID_HI, NODE_ID_LO) values (?, ?, ?)";
            nodeReferenceUpdateSQL =
                "update " + schemaObjectPrefix + "REFS"
                + " set REFS_DATA = ? where NODE_ID_HI = ? and NODE_ID_LO = ?";
            nodeReferenceSelectSQL = "select REFS_DATA from " + schemaObjectPrefix + "REFS where NODE_ID_HI = ? and NODE_ID_LO = ?";
            nodeReferenceDeleteSQL = "delete from " + schemaObjectPrefix + "REFS where NODE_ID_HI = ? and NODE_ID_LO = ?";

            bundleSelectAllIdsSQL = "select NODE_ID_HI, NODE_ID_LO from " + schemaObjectPrefix 
                + "BUNDLE ORDER BY NODE_ID_HI, NODE_ID_LO";
            // need to use HI and LO parameters
            // this is not the exact statement, but not all databases support WHERE (NODE_ID_HI, NODE_ID_LOW) >= (?, ?)
            bundleSelectAllIdsFromSQL =
                "select NODE_ID_HI, NODE_ID_LO from " + schemaObjectPrefix + "BUNDLE"
                + " WHERE (NODE_ID_HI >= ?) AND (? IS NOT NULL)"
                + " ORDER BY NODE_ID_HI, NODE_ID_LO";

            bundleSelectAllBundlesSQL = "select NODE_ID_HI, NODE_ID_LO, BUNDLE_DATA from " + schemaObjectPrefix
                    + "BUNDLE ORDER BY NODE_ID_HI, NODE_ID_LO";
            // need to use HI and LO parameters
            // this is not the exact statement, but not all databases support WHERE (NODE_ID_HI, NODE_ID_LOW) >= (?, ?)
            bundleSelectAllBundlesFromSQL =
                    "select NODE_ID_HI, NODE_ID_LO, BUNDLE_DATA from " + schemaObjectPrefix + "BUNDLE"
                            + " WHERE (NODE_ID_HI >= ?) AND (? IS NOT NULL)"
                            + " ORDER BY NODE_ID_HI, NODE_ID_LO";

        }

    }
1062910
private void addUniqueConstraintForTableBasedSequence(Statements statements, IdSourceKeyMetadata generatorKeyMetadata) {
		Statement statement = createUniqueConstraintStatement( generatorKeyMetadata.getKeyColumnName(), generatorKeyMetadata.getName() );
		statements.addStatement( statement );
	}