module texthelper.code_helper

Short summary

module pyquickhelper.texthelper.code_helper

Some functions about diacritics

source on GitHub

Functions

function

truncated documentation

_dictionary_to_dataframe

_measure_documentation_append

_measure_documentation_ratio

_measure_documentation_update

add_rst_links

Replaces words by something like :epkg:'word'.

change_style

Switches from AaBb into aa_bb.

measure_documentation

Measures the fact a module is documented.

measure_documentation_module

Measures the fact a module is documented.

Documentation

Some functions about diacritics

source on GitHub

pyquickhelper.texthelper.code_helper._dictionary_to_dataframe(doc, cols=None)[source]
pyquickhelper.texthelper.code_helper._measure_documentation_append(counts, kind, doc, code)[source]
pyquickhelper.texthelper.code_helper._measure_documentation_ratio(counts)[source]
pyquickhelper.texthelper.code_helper._measure_documentation_update(counts, c)[source]

Replaces words by something like :epkg:'word'.

Parameters:
  • text – text to process

  • values – values

  • tag – tag to use

  • n – number of consecutive words to look at

Returns:

new text

<<<

from pyquickhelper.texthelper import add_rst_links
text = "Maybe... Python is winning the competition for machine learning language."
values = {'Python': 'https://www.python.org/',
          'machine learning': 'https://en.wikipedia.org/wiki/Machine_learning'}
print(add_rst_links(text, values))

>>>

    Maybe... :epkg:`Python` is winning the competition for :epkg:`machine learning` language.

source on GitHub

pyquickhelper.texthelper.code_helper.change_style(name)[source]

Switches from AaBb into aa_bb.

Parameters:

name – name to convert

Returns:

converted name

Example:

<<<

from pyquickhelper.texthelper import change_style

print("changeStyle --> {0}".format(change_style('change_style')))

>>>

    changeStyle --> change_style

source on GitHub

pyquickhelper.texthelper.code_helper.measure_documentation(mod, ratio=False, include_hidden=False, f_kind=None, as_df=False)[source]

Measures the fact a module is documented.

Parameters:
  • mod – module

  • ratio – compute ratios

  • include_hidden – includes hidden function (starting with “_”)

  • f_kind – function f(obj: python_object) -> str which returns the fist key the result must be indexed by, the function cannot returns ‘function’ or ‘class’

  • as_df – return the result as a dataframe

Returns:

dictionary

<<<

import pprint
from pyquickhelper.texthelper import code_helper
from pyquickhelper.texthelper.code_helper import measure_documentation
pprint.pprint(measure_documentation(code_helper))

>>>

    {'function': {('length', 'code'): 5586,
                  ('length', 'doc'): 1923,
                  ('line', 'code'): 241,
                  ('line', 'doc'): 87,
                  ('raw_length', 'code'): 8539,
                  ('raw_length', 'doc'): 2397}}

source on GitHub

pyquickhelper.texthelper.code_helper.measure_documentation_module(mod, ratio=False, include_hidden=False, f_kind=None, silent=True, as_df=False)[source]

Measures the fact a module is documented.

Parameters:
  • mod – module or a list of modules, in case of a list of modules, a dictionary is returned per module

  • ratio – compute ratios

  • include_hidden – includes hidden function (starting with “_”)

  • f_kind – function f(obj: python_object) -> str which returns the fist key the result must be indexed by, the function cannot returns ‘function’ or ‘class’

  • silent – continue even if the import of a module failed

  • as_df – return the result as a dataframe

Returns:

dictionary

<<<

import pprint
import pyquickhelper
from pyquickhelper.texthelper.code_helper import measure_documentation_module
pprint.pprint(measure_documentation_module(pyquickhelper))

>>>

    {'function': {('length', 'code'): 10806,
                  ('length', 'doc'): 1988,
                  ('line', 'code'): 416,
                  ('line', 'doc'): 157,
                  ('raw_length', 'code'): 14242,
                  ('raw_length', 'doc'): 2546}}

source on GitHub