Defines where to put the dictionary output of the extractor in the doc, but renames
        the fields of the extracted output for the document or just filters the keys
4886
def set_output_fields(self, output_fields):
        """"""
        if isinstance(output_fields, dict) or isinstance(output_fields, list):
            self.output_fields = output_fields
        elif isinstance(output_fields, basestring):
            self.output_field = output_fields
        else:
            raise ValueError("set_output_fields requires a dictionary of "
                             + "output fields to remap, a list of keys to filter, or a scalar string")
        return self
822672
def _tool_to_dict(tool, records, remapped):
    
    requirements = _requirements_to_dict(tool.requirements + tool.hints)
    inputs = []
    outputs = []
    for inp in tool.tool["inputs"]:
        ready_inp, records = _input_to_dict(inp, records, remapped)
        inputs.append(ready_inp)
    for outp in tool.tool["outputs"]:
        ready_outp, records = _output_to_dict(outp, records)
        outputs.append(ready_outp)
    out = {"name": _id_to_name(tool.tool["id"]),
           "baseCommand": " ".join(tool.tool["baseCommand"]),
           "arguments": [_arg_to_dict(a, requirements) for a in tool.tool["arguments"]],
           "inputs": inputs,
           "outputs": outputs,
           "requirements": requirements,
           "stdin": None, "stdout": None}
    return out, records
1127461
def translate_doc(self, d, field_mapping=None, map_identifiers=None, **kwargs):
        
        if field_mapping is not None:
            self.map_doc(d, field_mapping)
        subject = self.translate_obj(d, M.SUBJECT)
        obj = self.translate_obj(d, M.OBJECT)

        # TODO: use a more robust method; we need equivalence as separate field in solr
        if map_identifiers is not None:
            if M.SUBJECT_CLOSURE in d:
                subject['id'] = self.map_id(subject, map_identifiers, d[M.SUBJECT_CLOSURE])
            else:
                logging.info("NO SUBJECT CLOSURE IN: "+str(d))

        if M.SUBJECT_TAXON in d:
            subject['taxon'] = self.translate_obj(d,M.SUBJECT_TAXON)
        if M.OBJECT_TAXON in d:
            obj['taxon'] = self.translate_obj(d, M.OBJECT_TAXON)

        qualifiers = []
        if M.RELATION in d and isinstance(d[M.RELATION],list):
            # GO overloads qualifiers and relation
            relation = None
            for rel in d[M.RELATION]:
                if rel.lower() == 'not':
                    qualifiers.append(rel)
                else:
                    relation = rel
            if relation is not None:
                d[M.RELATION] = relation
            else:
                d[M.RELATION] = None

        negated = 'not' in qualifiers

        assoc = {'id':d.get(M.ID),
                 'subject': subject,
                 'object': obj,
                 'negated': negated,
                 'relation': self.translate_obj(d,M.RELATION),
                 'publications': self.translate_objs(d,M.SOURCE),  # note 'source' is used in the golr schema
        }

        if self.invert_subject_object and assoc['relation'] is not None:
            assoc['relation']['inverse'] = True

        if len(qualifiers) > 0:
            assoc['qualifiers'] = qualifiers

        if M.OBJECT_CLOSURE in d:
            assoc['object_closure'] = d.get(M.OBJECT_CLOSURE)
        if M.IS_DEFINED_BY in d:
            if isinstance(d[M.IS_DEFINED_BY],list):
                assoc['provided_by'] = d[M.IS_DEFINED_BY]
            else:
                # hack for GO Golr instance
                assoc['provided_by'] = [d[M.IS_DEFINED_BY]]
        if M.EVIDENCE_OBJECT in d:
            assoc['evidence'] = d[M.EVIDENCE_OBJECT]
            assoc['types'] = [t for t in d[M.EVIDENCE_OBJECT] if t.startswith('ECO:')]

        if self._use_amigo_schema(self.object_category):
            for f in M.AMIGO_SPECIFIC_FIELDS:
                if f in d:
                    assoc[f] = d[f]

        # solr does not allow nested objects, so evidence graph is json-encoded
        if M.EVIDENCE_GRAPH in d:
            assoc[M.EVIDENCE_GRAPH] = json.loads(d[M.EVIDENCE_GRAPH])
        return assoc
923061
def remove_docstrings(tokens):
    
    prev_tok_type = None
    for index, tok in enumerate(tokens):
        token_type = tok[0]
        if token_type == tokenize.STRING:
            if prev_tok_type == tokenize.INDENT:
                # Definitely a docstring
                tokens[index][1] = '' # Remove it
                # Remove the leftover indentation and newline:
                tokens[index-1][1] = ''
                tokens[index-2][1] = ''
            elif prev_tok_type == tokenize.NL:
                # This captures whole-module docstrings:
                if tokens[index+1][0] == tokenize.NEWLINE:
                    tokens[index][1] = ''
                    # Remove the trailing newline:
                    tokens[index+1][1] = ''
        prev_tok_type = token_type
119136
function throwErrorOnUndefinedColumnName(keys, extract) {
    var regexRefs = /([a-zA-Z$_][\w$]+)(\s*\.\s*[a-zA-Z$_][\w$]+)*/g, // identifier[.identifier]...
        parts, variable;

    keys = keys.concat(['true', 'false']);

    // search for variable references, excluding property references (with dot operator prefix)
    while ((parts = regexRefs.exec(extract))) {
        variable = parts[1];
        if (keys.indexOf(variable) < 0) {
            throw new ReferenceError(variable + ' not defined.');
        }
    }
}
369915
def export(self, exclude=[]):
        
        fields = ( (key, self.get_field(key)) for key in self.schema
            if not key.startswith("_") and key not in exclude )
        
        doc = {name: field.export() for name, field in fields}
        return doc
539025
def content_fields
      output = {}

      # Include file content-related fields
      if is_a?(Jekyll::StaticFile)
        output["encoded_content"] = encoded_content
      elsif is_a?(JekyllAdmin::DataFile)
        output["content"] = content
        output["raw_content"] = raw_content
      else
        output["raw_content"] = raw_content
        output["front_matter"] = front_matter
      end

      # Include next and previous documents non-recursively
      if is_a?(Jekyll::Document)
        %w(next previous).each do |direction|
          method = "#{direction}_doc".to_sym
          doc = public_send(method)
          output[direction] = doc.to_api if doc
        end
      end

      output
    end
703823
def rename(dct, mapping):
    

    def _block(memo, key):
        if key in dct:
            memo[mapping[key]] = dct[key]
            return memo
        else:
            return memo
    return reduce(_block, mapping, omit(dct, *mapping.keys()))
589992
def convert_key_to_attr_names(cls, original):
    
    attrs = fields(cls)
    updated = {}
    keys_pulled = set()

    for a in attrs:
        key_name = a.metadata.get('key') or a.name
        if key_name in original:
            updated[a.name] = original.get(key_name)
            keys_pulled.add(key_name)

    if getattr(cls, '__related_strict__', False):
        extra = set(original.keys()) - keys_pulled
        if len(extra):
            raise ValueError("Extra keys (strict mode): {}".format(extra))

    return updated
474143
def get_output_jsonpath_with_name(self, sub_output=None):
        """"""
        if self.name is None:
            return None

        output_jsonpath_field = self.get_output_jsonpath_field(sub_output)
        extractor_filter = "name='{}'".format(self.name)
        output_jsonpath = "{}[?{}].(result[*][value])".format(
            output_jsonpath_field, extractor_filter)

        return output_jsonpath
373342
function generateNamedFieldExtractors(input) {
  var names = input.filter(function(matcher, index, array) {
    // has a name?
    return matcher.name;
  });
  // has duplicates?
  names.forEach(function(matcher, index, array) {
    var isDuplicate = array.slice(0, index).some(function(previousMatcher) {
      return previousMatcher.name == matcher.name;
    });
    if (isDuplicate) {
      throw new Error("duplicate named field '" + matcher.name + "'");
    }
  });
  return names;
}
1153450
def rename(self, mapping):
        
        for old_key, new_key in mapping:
            self.dict[new_key] = self.dict[old_key]
            del self.dict[old_key]
88492
def _delete_fields(self):
        
        for key in self._json_dict.keys():
            if not key.startswith("_"):
                delattr(self, key)
        self._json_dict = {}
        self.id = None
        self.name = None
666034
def extract!( *keys, &select_block )
      rv = subset( *keys, &select_block )
      rv.to_h.keys.each do |key|
        filter_parameters.delete( key )
      end
      rv
    end
411782
def _replace_fields(self, json_dict):
        
        for key in self._json_dict.keys():
            if not key.startswith("_"):
                delattr(self, key)
        self._json_dict = json_dict
        self._set_fields(json_dict)
336985
def reassemble(cls, fields, document):
        
        for field_name in cls._instructions:
            if field_name in fields:
                maker = cls._instructions[field_name]
                with maker.target(document):
                    document[field_name] = maker()
37878
def put_field(self, field):
        
        fpath = self.fields_json_path(field)
        # Open fields JSON, locking to prevent other processes
        # reading or writing
        with InterProcessLock(fpath + self.LOCK_SUFFIX, logger=logger):
            try:
                with open(fpath, 'r') as f:
                    dct = json.load(f)
            except IOError as e:
                if e.errno == errno.ENOENT:
                    dct = {}
                else:
                    raise
            if field.array:
                dct[field.name] = list(field.value)
            else:
                dct[field.name] = field.value
            with open(fpath, 'w') as f:
                json.dump(dct, f, indent=2)