Create a hash for an evidence and its citation.

    :param text: The evidence text
    :param type: The corresponding citation type
    :param reference: The citation reference
427995
def hash_evidence(text: str, type: str, reference: str) -> str:
    
    s = u'{type}:{reference}:{text}'.format(type=type, reference=reference, text=text)
    return hashlib.sha512(s.encode('utf8')).hexdigest()
656324
def build_references(citations, reference_format=False):
    
    # Now, run the method which will take as input:
    # 1. A list of lists of dictionaries, where each dictionary is a piece
    # of citation information corresponding to a tag in the citation.
    # 2. The line marker for this entire citation line (mulitple citation
    # 'finds' inside a single citation will use the same marker value)
    # The resulting xml line will be a properly marked up form of the
    # citation. It will take into account authors to try and split up
    # references which should be read as two SEPARATE ones.
    return [c for citation_elements in citations
            for elements in citation_elements['elements']
            for c in build_reference_fields(elements,
                                            citation_elements['line_marker'],
                                            citation_elements['raw_ref'],
                                            reference_format)]
1260892
def new(self, text):
        # type: (bytes) -> None
        '''
        
        '''
        if self._initialized:
            raise pycdlibexception.PyCdlibInternalError('This File or Text identifier is already initialized')

        if len(text) != 128:
            raise pycdlibexception.PyCdlibInvalidInput('Length of text must be 128')

        self.text = text

        self._initialized = True
741783
def from_text(cls, text, mapping='mapping'):
        
        graphemes = Counter(grapheme_pattern.findall(text))
        specs = [
            OrderedDict([
                (cls.GRAPHEME_COL, grapheme),
                ('frequency', frequency),
                (mapping, grapheme)])
            for grapheme, frequency in graphemes.most_common()]
        return cls(*specs)
842713
def build(self, text):
        
        super(Paragraph, self).build()
        self.content = text
393383
def fmt_data(text, data_formating = None, data_type = None):
        
        if data_type:
            return DATA_TYPES[data_type](text)
        elif data_formating:
            return str(data_formating).format(text)
        return str(text)
298460
def of_text(self, text, encoding="utf-8"):
        
        m = self.hash_algo()
        m.update(text.encode(encoding))
        if self.return_int:
            return int(m.hexdigest(), 16)
        else:
            return m.hexdigest()
86651
def analyse_text(text):
        
        result = 0.0
        lines = text.split('\n')
        hasEndProc = False
        hasHeaderComment = False
        hasFile = False
        hasJob = False
        hasProc = False
        hasParm = False
        hasReport = False

        def isCommentLine(line):
            return EasytrieveLexer._COMMENT_LINE_REGEX.match(lines[0]) is not None

        def isEmptyLine(line):
            return not bool(line.strip())

        # Remove possible empty lines and header comments.
        while lines and (isEmptyLine(lines[0]) or isCommentLine(lines[0])):
            if not isEmptyLine(lines[0]):
                hasHeaderComment = True
            del lines[0]

        if EasytrieveLexer._MACRO_HEADER_REGEX.match(lines[0]):
            # Looks like an Easytrieve macro.
            result = 0.4
            if hasHeaderComment:
                result += 0.4
        else:
            # Scan the source for lines starting with indicators.
            for line in lines:
                words = line.split()
                if (len(words) >= 2):
                    firstWord = words[0]
                    if not hasReport:
                        if not hasJob:
                            if not hasFile:
                                if not hasParm:
                                    if firstWord == 'PARM':
                                        hasParm = True
                                if firstWord == 'FILE':
                                    hasFile = True
                            if firstWord == 'JOB':
                                hasJob = True
                        elif firstWord == 'PROC':
                            hasProc = True
                        elif firstWord == 'END-PROC':
                            hasEndProc = True
                        elif firstWord == 'REPORT':
                            hasReport = True

            # Weight the findings.
            if hasJob and (hasProc == hasEndProc):
                if hasHeaderComment:
                    result += 0.1
                if hasParm:
                    if hasProc:
                        # Found PARM, JOB and PROC/END-PROC:
                        # pretty sure this is Easytrieve.
                        result += 0.8
                    else:
                        # Found PARAM and  JOB: probably this is Easytrieve
                        result += 0.5
                else:
                    # Found JOB and possibly other keywords: might be Easytrieve
                    result += 0.11
                    if hasParm:
                        # Note: PARAM is not a proper English word, so this is
                        # regarded a much better indicator for Easytrieve than
                        # the other words.
                        result += 0.2
                    if hasFile:
                        result += 0.01
                    if hasReport:
                        result += 0.01
        assert 0.0 <= result <= 1.0
        return result
496665
def with_text(self, text, markdown=None):
        '''
        '''
        self._text = text
        self._markdown = markdown or False

        return self
718511
def _get_evidence(self, event, adjectives):
        """"""
        provenance = event.get('provenance')

        # First try looking up the full sentence through provenance
        doc_id = provenance[0]['document']['@id']
        sent_id = provenance[0]['sentence']
        text = self.document_dict[doc_id]['sentences'][sent_id]
        text = self._sanitize(text)
        bounds = [provenance[0]['documentCharPositions'][k]
                  for k in ['start', 'end']]

        annotations = {
            'found_by': event.get('rule'),
            'provenance': provenance,
            'event_type': os.path.basename(event.get('type')),
            'adjectives': adjectives,
            'bounds': bounds
            }
        location = self.document_dict[doc_id]['location']
        ev = Evidence(source_api='hume', text=text, annotations=annotations,
                      pmid=location)
        return [ev]
886232
def add_text(self, text):
        
        t = self._r.add_t(text)
        return _Text(t)
48180
def _add_text(self, text):
        
        if text:
            if self.pending_nodes:
                self.pending_nodes[-1].append(nodes.Text(text))
            else:
                self.new_nodes.append(nodes.Text(text))
833101
def reference(node):
    
    o = nodes.reference()
    o['refuri'] = node.destination
    if node.title:
        o['name'] = node.title
    for n in MarkDown(node):
        o += n
    return o
1263760
def resolve_relative_rst_links(text: str, base_link: str):
    
    document = parse_rst(text)
    visitor = SimpleRefCounter(document)
    document.walk(visitor)
    for target in visitor.references:
        name = target.attributes['name']
        uri = target.attributes['refuri']
        new_link = '`{} <{}{}>`_'.format(name, base_link, uri)
        if name == uri:
            text = text.replace('`<{}>`_'.format(uri), new_link)
        else:
            text = text.replace('`{} <{}>`_'.format(name, uri), new_link)
    return text
566519
def add_reference(self, subj: Node, val: str) -> None:
        
        match = FHIR_RESOURCE_RE.match(val)
        ref_uri_str = res_type = None
        if match:
            ref_uri_str = val if match.group(FHIR_RE_BASE) else (self._base_uri + urllib.parse.quote(val))
            res_type = match.group(FHIR_RE_RESOURCE)
        elif '://' in val:
            ref_uri_str = val
            res_type = "Resource"
        elif self._base_uri and not val.startswith('#') and not val.startswith('/'):
            ref_uri_str = self._base_uri + urllib.parse.quote(val)
            res_type = val.split('/', 1)[0] if '/' in val else "Resource"
        if ref_uri_str:
            ref_uri = URIRef(ref_uri_str)
            self.add(subj, FHIR.link, ref_uri)
            self.add(ref_uri, RDF.type, FHIR[res_type])
930768
def get_citation_by_hash(self, citation_hash: str) -> Optional[Citation]:
        """"""
        return self.session.query(Citation).filter(Citation.sha512 == citation_hash).one_or_none()
796836
def fmt_text(text, bg = None, fg = None, attr = None, plain = False):
        
        if not plain:
            if fg is not None:
                text = TEXT_FORMATING['fg'][fg] + text
            if bg is not None:
                text = TEXT_FORMATING['bg'][bg] + text
            if attr is not None:
                text = TEXT_FORMATING['attr'][attr] + text
            if (fg is not None) or (bg is not None) or (attr is not None):
                text += TEXT_FORMATING['rst']
        return text