Exemplo n.º 1
0
def malformed_query_warning_html(bad_search_txt):
    warning_header_txt = f'Oops, we didn\'t understand that search.'
    warning_body_txt = \
        f'\n Your search was: "{bad_search_txt}"\n. Try the format entity1: ' \
        f'value1, entity2: value2. For example: "material: PbTe, ' \
        f'property: thermoelectric"'
    return common_warning_html(warning_header_txt, warning_body_txt)
Exemplo n.º 2
0
def malformed_query_warning_html(bad_search_txt):
    """
    The html block when a query is malformed and searched.

    Args:
        bad_search_txt (str): The search text.

    Returns:
        (dash_html_components.Div): The html block when a malformed query is
            entered and searched.
    """
    warning_header_txt = f"Oops, we didn't understand that search."
    warning_body_txt = (
        f'\n Your search was: "{bad_search_txt}"\n. Try the format entity1: '
        f'value1, entity2: value2. For example: "material: PbTe, '
        f'property: thermoelectric"')
    return common_warning_html(warning_header_txt, warning_body_txt, "is-half")
Exemplo n.º 3
0
def abstracts_entities_results_html(text, normalize):
    # Extract highlighted
    try:
        result = rester.get_ner_tags(text, concatenate=True, normalize=normalize)
    except MatScholarRestError:
        rester_error_txt = \
            "Our server is having trouble with that abstract. We are likely " \
            "undergoing maintenance, check back soon!"
        return common_rester_error_html(rester_error_txt)
    tagged_doc = result["tags"]
    relevance = result["relevance"]
    highlighted = highlight_entities(tagged_doc)

    # Add the warning
    if not relevance:
        warning_header_txt = "Warning! Abstract not relevant."
        warning_body_txt = \
            "Our classifier has flagged this document as not relevant to " \
            "inorganic materials science. Expect lower than optimum " \
            "performance."
        warning = common_warning_html(warning_header_txt, warning_body_txt)
    else:
        warning = html.Div("")

    # Update download link
    doc = {"sentences": []}
    for sent in tagged_doc:
        new_sent = []
        for token, tag in sent:
            new_sent.append({"token": token, "tag": tag})
        doc["sentences"].append(new_sent)
    json_string = json.dumps(doc)
    json_string = "data:text/csv;charset=utf-8," + \
                  urllib.parse.quote(json_string)
    download_link = html.A(
        "Download entities as json",
        id="entity-download-link",
        href=json_string,
        download="tagged_docs.json",
        target="_blank"
    )
    download_container = html.Div(
        download_link,
        className="has-text-size-4 has-margin-top 10"
    )

    label = html.Label("Extracted Entity Tags:")
    label_container = html.Div(label,
                               className="is-size-4 has-margin-top-30")

    highlighted_container = html.Div(highlighted)

    label_label = html.Label("Labels:")
    label_label_container = html.Div(label_label,
                                     className="is-size-4 has-margin-top-30")

    entity_colormap_key = copy.deepcopy(entity_color_map_extended)
    entities_keys = []
    for e, color in entity_colormap_key.items():
        # don't need the "other" label
        if e == "other":
            continue
        entity_key = html.Div(e, className=f"is-size-4 msweb-is-{color}-txt has-text-weight-bold")
        entity_key_container = html.Div(
            entity_key,
            className="flex-column is-narrow has-margin-5 box"
        )
        entities_keys.append(entity_key_container)

    entity_key_container = html.Div(
        entities_keys,
        className="columns is-multiline has-margin-5"
    )

    results = html.Div(
        [
            warning,
            label_container,
            highlighted_container,
            label_label_container,
            entity_key_container,
            download_container
        ]
    )
    return results
Exemplo n.º 4
0
def extract_entities_results_html(text, normalize):
    """
    Get an html block of the results for an entity extraction.

    Args:
        text (str): The abstract text to extract entities from.
        normalize (bool): Whether to normalize the entities or not.

    Returns:
        (dash_html_components.Div): The html block for the entity extraction
            results.
    """
    try:
        result = rester.get_ner_tags(text,
                                     concatenate=True,
                                     normalize=normalize)
    except MatScholarRestError:
        rester_error_txt = RESTER_ERROR_TEXT
        return common_rester_error_html(rester_error_txt)
    tagged_doc = result["tags"]
    relevance = result["relevance"]
    highlighted = highlight_entities_html(tagged_doc)

    # Add the warning
    if not relevance:
        warning_header_txt = "Warning! Abstract not relevant."
        warning_body_txt = (
            "Our classifier has flagged this document as not relevant to "
            "inorganic materials science. Expect lower than optimum "
            "performance.")
        warning = common_warning_html(warning_header_txt, warning_body_txt,
                                      "is-fullwidth")
    else:
        warning = html.Div("")

    # Update download link
    doc = {"sentences": []}
    for sent in tagged_doc:
        new_sent = []
        for token, tag in sent:
            new_sent.append({"token": token, "tag": tag})
        doc["sentences"].append(new_sent)
    json_string = json.dumps(doc)
    json_string = "data:text/csv;charset=utf-8," + urllib.parse.quote(
        json_string)
    download_link = html.A(
        "Download entities as json",
        id="entity-download-link",
        href=json_string,
        download="tagged_docs.json",
        target="_blank",
    )
    download_container = html.Div(
        download_link, className="has-text-size-4 has-margin-top 10")

    label = html.Label("Extracted Entity Tags:")
    label_container = html.Div(label, className="is-size-4 has-margin-top-30")

    highlighted_container = html.Div(highlighted)

    label_label = html.Label("Labels:")
    label_label_container = html.Div(label_label,
                                     className="is-size-4 has-margin-top-30")

    entity_colormap_key = copy.deepcopy(entity_color_map_extended)
    entities_keys = []
    for e, color in entity_colormap_key.items():
        # don't need the "other" label
        if e == "other":
            continue
        entity_key = html.Div(
            e,
            className=f"is-size-4 msweb-is-{color}-txt has-text-weight-bold")
        entity_key_container = html.Div(
            entity_key, className="flex-column is-narrow has-margin-5 box")
        entities_keys.append(entity_key_container)

    entity_key_container = html.Div(
        entities_keys, className="columns is-multiline has-margin-5")

    results = html.Div([
        warning,
        label_container,
        highlighted_container,
        label_label_container,
        entity_key_container,
        download_container,
    ])
    return results