Methods related with extracting documentation strings.
176833
@Override
    public Map<String, String> loadDocStrings(Set<ServiceConfig> serviceConfigs) {
        return serviceConfigs.stream()
                             .flatMap(c -> c.service().as(THttpService.class).get().entries().values().stream())
                             .flatMap(entry -> entry.interfaces().stream().map(Class::getClassLoader))
                             .flatMap(loader -> docstringExtractor.getAllDocStrings(loader)
                                                                  .entrySet().stream())
                             .collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> a));
    }
857875
def getdoc(object):
    """"""
    try:
        doc = object.__doc__
    except AttributeError:
        return None
    if not isinstance(doc, (str, unicode)):
        return None
    try:
        lines = string.split(string.expandtabs(doc), '\n')
    except UnicodeError:
        return None
    else:
        margin = None
        for line in lines[1:]:
            content = len(string.lstrip(line))
            if not content: continue
            indent = len(line) - content
            if margin is None: margin = indent
            else: margin = min(margin, indent)
        if margin is not None:
            for i in range(1, len(lines)): lines[i] = lines[i][margin:]
        return string.join(lines, '\n')
509341
function(string) {
    var translated = Documentation.TRANSLATIONS[string];
    if (typeof translated == 'undefined')
      return string;
    return (typeof translated == 'string') ? translated : translated[0];
  }
773607
def extract(filepath, taxonomy, output_mode, output_limit,
            spires, match_mode, detect_author_keywords, extract_acronyms,
            rebuild_cache, only_core_tags, no_cache):
    """"""
    if not filepath or not taxonomy:
        print("No PDF file or taxonomy given!", file=sys.stderr)
        sys.exit(0)

    click.echo(
        ">>> Going extract keywords from {0} as '{1}'...".format(
            filepath, output_mode
        )
    )
    if not os.path.isfile(filepath):
        click.echo(
            "Path to non-existing file\n",
        )
        sys.exit(1)

    result = get_keywords_from_local_file(
        local_file=filepath,
        taxonomy_name=taxonomy,
        output_mode=output_mode,
        output_limit=output_limit,
        spires=spires,
        match_mode=match_mode,
        no_cache=no_cache,
        with_author_keywords=detect_author_keywords,
        rebuild_cache=rebuild_cache,
        only_core_tags=only_core_tags,
        extract_acronyms=extract_acronyms
    )
    click.echo(result)
148042
def _extract_methods(self):
        """"""
        service = self._service
        all_urls = set()
        urls_with_options = set()
        if not service.http:
            return
        for rule in service.http.rules:
            http_method, url = _detect_pattern_option(rule)
            if not url or not http_method or not rule.selector:
                _logger.error(u'invalid HTTP binding encountered')
                continue

            # Obtain the method info
            method_info = self._get_or_create_method_info(rule.selector)
            if rule.body:
                method_info.body_field_path = rule.body
            if not self._register(http_method, url, method_info):
                continue  # detected an invalid url
            all_urls.add(url)

            if http_method == self._OPTIONS:
                urls_with_options.add(url)

        self._add_cors_options_selectors(all_urls - urls_with_options)
        self._update_usage()
        self._update_system_parameters()
633342
def get_description_from_docstring(cls, obj):
    
    doc = obj.__doc__ or ''
    p = doc.find('\n')
    if p == -1:
      return doc, []
    else:
      description = doc[:p]
      details = textwrap.dedent(doc[p+1:]).splitlines()
      # Remove leading and trailing empty lines.
      while details and not details[0].strip():
        details = details[1:]
      while details and not details[-1].strip():
        details.pop()

      recording = True
      details_without_params = []
      for detail_line in details:
        if ":param" in detail_line:
          recording = False
        if not detail_line.strip():
          recording = True
        if recording:
          details_without_params.append(detail_line)
      return description, details_without_params
310270
def get_variable_docstrings(filename):
    

    def walk_node(parent, values=None, prefix=""):
        """
        walk the ast searching for docstrings/values
        """
        docstrings = {}
        if values is None:
            values = {}
        key = None
        for node in ast.iter_child_nodes(parent):
            if isinstance(node, ast.ClassDef):
                # We are in a class so walk the class
                docs = walk_node(node, values, prefix + node.name + ".")[0]
                docstrings[node.name] = docs
            elif isinstance(node, ast.Assign):
                key = node.targets[0].id
                if isinstance(node.value, ast.Num):
                    values[key] = node.value.n
                if isinstance(node.value, ast.Str):
                    values[key] = node.value.s
                if isinstance(node.value, ast.Name):
                    if node.value.id in values:
                        values[prefix + key] = values[node.value.id]
            elif isinstance(node, ast.Expr) and key:
                docstrings[key] = node.value.s
            else:
                key = None
        return docstrings, values

    with open(filename, "r") as f:
        source = f.read()
    return walk_node(ast.parse(source))
1272717
def _parse_doc(doc):
    
    lines = doc.split("\n")
    descriptions = list(itertools.takewhile(_checker(_KEYWORDS), lines))

    if len(descriptions) < 3:
        description = lines[0]
    else:
        description = "{0}\n\n{1}".format(
            lines[0], textwrap.dedent("\n".join(descriptions[2:])))

    args = list(itertools.takewhile(
        _checker(_KEYWORDS_OTHERS),
        itertools.dropwhile(_checker(_KEYWORDS_ARGS), lines)))
    argmap = {}
    if len(args) > 1:
        for pair in args[1:]:
            kv = [v.strip() for v in pair.split(":")]
            if len(kv) >= 2:
                argmap[kv[0]] = ":".join(kv[1:])

    return dict(headline=descriptions[0], description=description, args=argmap)
1342852
def parse_doc(doc):
    """"""
    word_spans = []
    sentence_spans = []
    sentence_chunks = doc.split('\n\n')
    sentences = []
    for chunk in sentence_chunks:
        sent_texts, sent_labels = get_texts_and_labels(chunk.strip())
        sentences.append(list(zip(sent_texts, sent_labels)))
    return sentences
1082467
def _extract_docs_description(self):
        """"""
        # FIXME: the indentation of descriptions is lost
        data = '\n'.join([d.rstrip().replace(self.docs['out']['spaces'], '', 1) for d in self.docs['in']['raw'].splitlines()])
        if self.dst.style['in'] == 'groups':
            idx = self.dst.get_group_index(data)
        elif self.dst.style['in'] == 'google':
            lines = data.splitlines()
            line_num = self.dst.googledoc.get_next_section_start_line(lines)
            if line_num == -1:
                idx = -1
            else:
                idx = len('\n'.join(lines[:line_num]))
        elif self.dst.style['in'] == 'numpydoc':
            lines = data.splitlines()
            line_num = self.dst.numpydoc.get_next_section_start_line(lines)
            if line_num == -1:
                idx = -1
            else:
                idx = len('\n'.join(lines[:line_num]))
        elif self.dst.style['in'] == 'unknown':
            idx = -1
        else:
            idx = self.dst.get_elem_index(data)
        if idx == 0:
            self.docs['in']['desc'] = ''
        elif idx == -1:
            self.docs['in']['desc'] = data
        else:
            self.docs['in']['desc'] = data[:idx]
321816
def _load_documentation(self, term, contents, file_name):
        """"""

        try:
            title = term['title'].value
        except KeyError:
            self.warn("Documentation has no title, skipping: '{}' ".format(term.value))
            return

        if term.term_is('Root.Readme'): # This term type has inline content, not a url
            package_sub_dir = 'docs'
        else:
            try:
                eu = term.expanded_url
                parsed_url = term.parsed_url
            except AttributeError:
                parsed_url = eu = parse_app_url(term.value)

            # Can't used expanded_url here because expansion makes file system URLS absolute.
            if eu.proto == 'file' and not parsed_url.path_is_absolute:
                package_sub_dir = parsed_url.fspath.parent
            else:
                package_sub_dir = 'docs'


        path = join(self.package_path.path,  package_sub_dir, file_name)

        self.prt("Loading documentation for '{}', '{}' to '{}'  ".format(title, file_name, path))

        makedirs(dirname(path), exist_ok=True)

        if exists(path):
            remove(path)

        with open(path, 'wb') as f:
            f.write(contents)
858768
def extract_paragraphs(xml_string):
    """"""
    assert isinstance(xml_string, str)
    xml_tree = ET.XML(xml_string.encode('utf-8'), parser=UTB())
    full_text = xml_tree.find('article:originalText', elsevier_ns)
    if full_text is None:
        logger.info('Could not find full text element article:originalText')
        return None
    article_body = _get_article_body(full_text)
    if article_body:
        return article_body
    raw_text = _get_raw_text(full_text)
    if raw_text:
        return [raw_text]
    return None
447475
def parse_doc(doc):
    """"""
    if doc is None:
        return {}

    out = {}

    sections = re.split(r'(\w+)\n\s+-{4,50}', doc)  # obj.__doc__.split('\n\n')
    intro = sections.pop(0)
    if intro:
        content = list(map(str.strip, intro.strip().split('\n\n')))
        if len(content) == 1:
            out['title'] = content[0]
        elif len(content) == 2:
            out['title'], out['abstract'] = content

    for i in range(0, len(sections), 2):
        header, content = sections[i:i + 2]

        if header in ['Notes', 'References']:
            out[header.lower()] = content.replace('\n    ', '\n')
        elif header == 'Parameters':
            pass
        elif header == 'Returns':
            match = re.search(r'xarray\.DataArray\s*(.*)', content)
            if match:
                out['long_name'] = match.groups()[0]

    return out
1185271
def extract_from_renamed_inputs(self, doc, renamed_inputs):
        """"""
        extracted_value = self.extractor.extract(renamed_inputs)
        if not extracted_value:
            return doc

        if self.output_fields is not None and isinstance(extracted_value, dict):
            if isinstance(self.output_fields, list):
                for field in self.output_fields:
                    if field in extracted_value:
                        self.insert_extracted_value(
                            doc, extracted_value[field], field)
            elif isinstance(self.output_fields, dict):
                for key, value in self.output_fields.iteritems():
                    if key in extracted_value:
                        self.insert_extracted_value(
                            doc, extracted_value[key], value, key)
        else:
            self.insert_extracted_value(
                doc, extracted_value, self.output_field)
61543
def _extract_attrs(x, n):
    
    try:
        return extract_attrs(x, n)

    except (ValueError, IndexError):

        if PANDOCVERSION < '1.16':
            # Look for attributes attached to the image path, as occurs with
            # image references for pandoc < 1.16 (pandoc-fignos Issue #14).
            # See http://pandoc.org/MANUAL.html#images for the syntax.
            # Note: This code does not handle the "optional title" for
            # image references (search for link_attributes in pandoc's docs).
            assert x[n-1]['t'] == 'Image'
            image = x[n-1]
            s = image['c'][-1][0]
            if '%20%7B' in s:
                path = s[:s.index('%20%7B')]
                attrs = unquote(s[s.index('%7B'):])
                image['c'][-1][0] = path  # Remove attr string from the path
                return PandocAttributes(attrs.strip(), 'markdown').to_pandoc()
        raise
701036
def extract(self, text: str) -> List[Extraction]:
        

        doc = self._tokenizer.tokenize_to_spacy_doc(text)
        self._load_matcher()

        matches = [x for x in self._matcher(doc) if x[1] != x[2]]
        pos_filtered_matches = []
        neg_filtered_matches = []
        for idx, start, end in matches:
            span_doc = self._tokenizer.tokenize_to_spacy_doc(doc[start:end].text)
            this_spacy_rule = self._matcher.get(idx)
            relations = self._find_relation(span_doc, this_spacy_rule)
            rule_id, _ = self._hash_map[idx]
            this_rule = self._rule_lst[rule_id]
            if self._filter_match(doc[start:end], relations, this_rule.patterns):
                value = self._form_output(doc[start:end], this_rule.output_format, relations, this_rule.patterns)
                if this_rule.polarity:
                    pos_filtered_matches.append((start, end, value, rule_id, relations))
                else:
                    neg_filtered_matches.append((start, end, value, rule_id, relations))

        return_lst = []
        if pos_filtered_matches:
            longest_lst_pos = self._get_longest(pos_filtered_matches)
            if neg_filtered_matches:
                longest_lst_neg = self._get_longest(neg_filtered_matches)
                return_lst = self._reject_neg(longest_lst_pos, longest_lst_neg)
            else:
                return_lst = longest_lst_pos

        extractions = []
        for (start, end, value, rule_id, relation) in return_lst:
            this_extraction = Extraction(value=value,
                                         extractor_name=self.name,
                                         start_token=start,
                                         end_token=end,
                                         start_char=doc[start].idx,
                                         end_char=doc[end-1].idx+len(doc[end-1]),
                                         rule_id=rule_id.split("rule_id##")[0],
                                         match_mapping=relation)
            extractions.append(this_extraction)

        return extractions
120378
def check_docstring(self, method):
        ''''''
        mn = method.__name__
        if method.__doc__ is None:
            return ['Missing docstring for method "{}"'.format(mn)]