returns transformed doc according to ruleTree
341150
function (doc, ruleTree) {
    // Special case for "sets"
    if (_.isArray(doc))
      return _.map(doc, function (subdoc) { return transform(subdoc, ruleTree); });

    var res = details.including ? {} : EJSON.clone(doc);
    _.each(ruleTree, function (rule, key) {
      if (!_.has(doc, key))
        return;
      if (_.isObject(rule)) {
        // For sub-objects/subsets we branch
        if (_.isObject(doc[key]))
          res[key] = transform(doc[key], rule);
        // Otherwise we don't even touch this subfield
      } else if (details.including)
        res[key] = EJSON.clone(doc[key]);
      else
        delete res[key];
    });

    return res;
  }
576571
def splitted_rules(root):
    # type: (Nonterminal) -> Nonterminal
    
    items = Traversing.post_order(root)
    items = filter(lambda x: isinstance(x, SplitRule), items)
    for i in items:
        # create the original rule
        newRule = i.from_rule()
        # replace it with the node in the tree
        Manipulations.replace(i, newRule)
    return root
51370
def _generate_doc(ret):
    '''
    
    '''

    # Create a copy of the object that we will return.
    retc = ret.copy()

    # Set the ID of the document to be the JID.
    retc["_id"] = ret["jid"]

    # Add a timestamp field to the document
    retc["timestamp"] = time.time()

    return retc
1121547
def transform_incoming(self, son, collection):
        """"""
        return self._transform_incoming(copy.deepcopy(son), collection)
1303809
def _loadChildRules(context, xmlElement, attributeToFormatMap):
    
    rules = []
    for ruleElement in xmlElement.getchildren():
        if not ruleElement.tag in _ruleClassDict:
            raise ValueError("Not supported rule '%s'" % ruleElement.tag)
        rule = _ruleClassDict[ruleElement.tag](context, ruleElement, attributeToFormatMap)
        rules.append(rule)
    return rules
559853
def _get_doc():
    ''''''
    def get_docstring(func):
        '''extract doctstring, if possible'''
        docstring = ':\n'
        if func.__doc__:
            docstring += _indent(func.__doc__, 2)
        return docstring

    ret = ['\nNeurite features (neurite, neuron, neuron population):']
    ret.extend(_INDENT + '- ' + feature + get_docstring(func)
               for feature, func in sorted(NEURITEFEATURES.items()))

    ret.append('\nNeuron features (neuron, neuron population):')
    ret.extend(_INDENT + '- ' + feature + get_docstring(func)
               for feature, func in sorted(NEURONFEATURES.items()))

    return '\n'.join(ret)
1065196
function result(rule) {
  var r = {}

  var reserved = ['filename', 'exists', 'grep', 'jsonKeyExists']

  Object.keys(rule).forEach(function(key) {
    if (reserved.indexOf(key) !== -1) return
    r[key] = rule[key]
  })

  return r
}
424159
function transform( node ) {
	var type;
	if ( node.type ) {
		if ( node.type.length === 1 ) {
			type = node.type[ 0 ];
		} else {
			type = node.type;
		}
	} else {
		type = '';
	}
	return {
		'name': node.name,
		'description': node.description || '',
		'type': type,
		'access': node.access || '',
		'virtual': !!node.virtual
	};
}
347891
def get_rendered_toctree(builder, docname, prune=False, collapse=True):
    
    fulltoc = build_full_toctree(builder,
                                 docname,
                                 prune=prune,
                                 collapse=collapse,
                                 )
    rendered_toc = builder.render_partial(fulltoc)['fragment']
    return rendered_toc
1060209
def doc(self):
        
        ret = libxml2mod.xmlParserGetDoc(self._o)
        if ret is None:raise parserError('xmlParserGetDoc() failed')
        __tmp = xmlDoc(_obj=ret)
        return __tmp
331042
def extract(self, doc):
        
        if isinstance(self.jsonpaths, JSONPath):
            input_field = self.extractor.get_renamed_input_fields()
            if isinstance(self.extractor.get_renamed_input_fields(), list):
                input_field = input_field[0]

            jsonpath = self.jsonpaths
            renamed_inputs = dict()
            if self.flat_map_inputs:
                flat_mapped = itertools.chain.from_iterable(
                    [iter(match.value)
                     if hasattr(match.value, '__iter__') and
                     not isinstance(match.value, dict) and
                     not isinstance(match.value, basestring)
                     else iter([match.value])
                     for match in jsonpath.find(doc)])
                renamed_inputs[input_field] = flat_mapped
                if input_field in renamed_inputs:
                    self.extract_from_renamed_inputs(doc, renamed_inputs)

            else:
                for value in [match.value for match in jsonpath.find(doc)]:
                    renamed_inputs[input_field] = value
                    self.extract_from_renamed_inputs(doc, renamed_inputs)

        elif isinstance(self.jsonpaths, types.ListType):

            renamed_inputs_lists = dict()
            for jsonpath, renamed_input in \
                    itertools.izip(
                    iter(self.jsonpaths),
                    iter(self.extractor.get_renamed_input_fields())):
                renamed_inputs_lists[renamed_input] = [
                    match.value for match in jsonpath.find(doc)]

            if self.flat_map_inputs:
                renamed_inputs_tuple_lists = [
                    (x, itertools.chain.from_iterable(
                        [iter(z) if hasattr(z, '__iter__') and
                         not isinstance(z, dict) and
                         not isinstance(z, basestring)
                         else iter([z])for z in y]))
                    for x, y in renamed_inputs_lists.iteritems()]
                renamed_inputs = reduce(
                    ExtractorProcessor.add_tuple_to_doc,
                    renamed_inputs_tuple_lists, dict())
                self.extract_from_renamed_inputs(doc, renamed_inputs)
            else:
                renamed_inputs_lists_lists = [[(x, z) for z in y]
                                              for x, y in
                                              renamed_inputs_lists.iteritems()]
                for i in itertools.product(*renamed_inputs_lists_lists):
                    renamed_inputs = reduce(
                        ExtractorProcessor.add_tuple_to_doc, i, dict())
                    self.extract_from_renamed_inputs(doc, renamed_inputs)
        else:
            raise ValueError("input_fields must be a string or a list")

        return doc
1121406
def get_feats(self, doc):
		'''
		
		'''
		return Counter([str(c).lower() for c in doc.noun_chunks])
1352290
function(doc, node, textFormat){
			var out;
			this.textFormat = (textFormat)? textFormat : this.textFormat;
			if(this.textFormat === 'normalised'){
				out = this.walkTreeForText( node );
				if(out !== undefined){
					return this.normalise( doc, out );
				}else{
					return '';
				}
			}else{
				var clonedNode = modules.domUtils.clone(node);
				var trimmedNode = modules.domUtils.removeDescendantsByTagName( clonedNode, this.excludeTags );

			   return this.formatText( doc, modules.domUtils.textContent(trimmedNode), this.textFormat );
			}
		}
263135
function collect(node, options, context, variables={}) {
    for (let rule of node.rules) {
        if (rule.isRuleset)
            collect(rule, options, context, variables);
        else if (rule.importedFilename)
            collect(rule.root, options, context, variables);
        else if (rule.variable === true) {
            const name = rule.name.substring(1);
            const value = rule.value.eval(context);

            // save under all aliases
            for (let fn of options.rename) {
                variables[ fn(name) ] = toJS(value, options, context);
            }
        }
    }

    return variables;
}
125869
function getElementNameForTransformation( rule, check ) {
		if ( rule.element )
			return rule.element;
		if ( check )
			return check.match( /^([a-z0-9]+)/i )[ 0 ];
		return rule.left.getDefinition().element;
	}
625745
def get_collection_tree(collection_ident, cursor):
    """"""
    cursor.execute('''
    WITH RECURSIVE t(node, parent, document, path) AS (
        SELECT tr.nodeid, tr.parent_id, tr.documentid, ARRAY[tr.nodeid]
        FROM trees tr
        WHERE tr.documentid = %s and tr.is_collated = 'False'
    UNION ALL
        SELECT c.nodeid, c.parent_id, c.documentid, path || ARRAY[c.nodeid]
        FROM trees c JOIN t ON c.parent_id = t.node
        WHERE NOT c.nodeid = ANY(t.path)
    )
    SELECT t.document, m.portal_type
    FROM t JOIN modules m
    ON t.document = m.module_ident''', [collection_ident])
    for i in cursor.fetchall():
        yield i
1252541
def recoverDoc(cur):
    
    ret = libxml2mod.xmlRecoverDoc(cur)
    if ret is None:raise treeError('xmlRecoverDoc() failed')
    return xmlDoc(_obj=ret)