Esempio n. 1
0
def everything_results_html(entity_query, raw_text):
    """
    Get the html block for all results from the Rester-compatible
    entity query and text. Results are concatenated.

    Args:
        entity_query (dict): The entity query, in Rester-compatible format.
        raw_text (str, None): Any raw text to search for.

    Returns:
        (dash_html_components.Div): The results html block for all search
            types concatenated.

    """
    scroll_down_header_txt = "Scroll down for more results."
    scroll_down_header = html.Div(scroll_down_header_txt,
                                  className="is-size-3")
    scroll_down = html.Div(
        [scroll_down_header],
        className="notification is-light has-text-centered",
    )
    scroll_down_column = html.Div(scroll_down, className="column is-half")
    scroll_down_columns = html.Div(scroll_down_column,
                                   className="columns is-centered")
    scroll_down_container = html.Div(scroll_down_columns,
                                     className="container")

    entities_results = entities_results_html(entity_query, raw_text)
    materials_results = materials_results_html(entity_query, raw_text)
    abstracts_results = abstracts_results_html(entity_query, raw_text)
    no_results = no_results_html(pre_label=None)

    if all([
            entities_results == entities_no_results_html,
            materials_results == materials_no_results_html,
            abstracts_results == abstracts_no_results_html,
    ]):
        return no_results
    else:
        container = html.Div(
            [
                scroll_down_container,
                entities_results,
                materials_results,
                abstracts_results,
            ],
            className="container",
        )
        return container
Esempio n. 2
0
def abstracts_results_html(entity_query, raw_text):
    """
    Get the html block for abstracts results from the Rester-compatible
    entity query and text.

    Args:
        entity_query (dict): The entity query, in Rester-compatible format.
        raw_text (str, None): Any raw text to search for.

    Returns:
        (dash_html_components.Div): The abstracts results html block.

    """
    results = rester.abstracts_search(entity_query,
                                      text=raw_text,
                                      top_k=MAX_N_ABSTRACTS_RETRIEVED)

    if not results:
        return abstracts_no_results_html
    else:
        df = pd.DataFrame(results)
        n_raw_results = df.shape[0]

        if df.empty:
            return no_results_html()

        df["authors"] = df["authors"].apply(format_authors)

        n_formatted_results = min(len(df), MAX_N_ABSTRACTS_SHOWN)
        formatted_results = [None] * n_formatted_results

        if n_raw_results >= MAX_N_ABSTRACTS_SHOWN:
            label_txt = (
                f"Showing {n_formatted_results} of many results. For full "
                f"results, use the ")
            label_link = html.A(
                "Matscholar API.",
                href="https://github.com/materialsintelligence/matscholar",
            )
            label = html.Label([label_txt, label_link])
        else:
            label_txt = f"Showing all {n_raw_results} results."
            label = html.Label(label_txt)

        entities_keys = []
        for e in valid_entity_filters:
            color = entity_color_map[e]
            entity_colored = html.Div(
                e,
                className=
                f"msweb-is-{color}-txt is-size-5 has-text-weight-bold",
            )
            entity_key = html.Div(entity_colored,
                                  className=f"box has-padding-5")
            entity_key_container = html.Div(
                entity_key, className="flex-column is-narrow has-margin-5")
            entities_keys.append(entity_key_container)
        entity_key_container = html.Div(
            entities_keys, className="columns is-multiline has-margin-5")

        for i in range(n_formatted_results):
            formatted_results[i] = format_result_html(df.iloc[i])
        paper_table = html.Table(
            formatted_results,
            className=
            "table is-fullwidth is-bordered is-hoverable is-narrow is-striped",
        )

        return html.Div(
            [
                big_label_and_disclaimer,
                label,
                entity_key_container,
                paper_table,
            ],
            className=common_results_container_style(),
        )
Esempio n. 3
0
from matscholar_web.search.common import (
    big_label_and_disclaimer_html,
    common_results_container_style,
    no_results_html,
)
"""
Functions for defining the results container when abstract results are desired.

Please do not define callback logic in this file.
"""

MAX_N_ABSTRACTS_RETRIEVED = 200  # the number of abstracts retrieved via api
MAX_N_ABSTRACTS_SHOWN = 20  # the number of abstracts actually shown

big_label_and_disclaimer = big_label_and_disclaimer_html("abstracts")
abstracts_no_results_html = no_results_html(pre_label=big_label_and_disclaimer)


def abstracts_results_html(entity_query, raw_text):
    """
    Get the html block for abstracts results from the Rester-compatible
    entity query and text.

    Args:
        entity_query (dict): The entity query, in Rester-compatible format.
        raw_text (str, None): Any raw text to search for.

    Returns:
        (dash_html_components.Div): The abstracts results html block.

    """
Esempio n. 4
0
def materials_results_html(entity_query, raw_text):
    """
    Get the html block for materials summaru from the Rester-compatible
    entity query and text.

    Args:
        entity_query (dict): The entity query, in Rester-compatible format.
        raw_text (str, None): Any raw text to search for.

    Returns:
        (dash_html_components.Div): The materials summary html block.
    """
    results = rester.materials_search(entity_query,
                                      text=raw_text,
                                      top_k=MAX_N_MATERIALS_IN_TABLE)

    if not results:
        return materials_no_results_html
    else:
        materials = []
        counts = []
        dois = []

        for i, r in enumerate(results):
            material = r["material"]
            elemental = len(material) <= 2
            oxide = "oxide" in material
            uppercase = material.isupper()
            if not uppercase and not oxide and not elemental:
                materials.append(material)
                counts.append(r["count"])
                dois.append(r["dois"])

        df = pd.DataFrame({
            "material": materials,
            "count": counts,
            "dois": dois
        })

        # Prevent results with only oxides or elements from being shown
        # as an empty table
        if df.shape[0] == 0:
            return no_results_html(pre_label=big_results_label_and_disclaimer)

        # Update the download link
        link = make_download_link_from_all_dois_html(df)

        n_filtered_results = df.shape[0]
        if n_filtered_results >= MAX_N_MATERIALS_IN_TABLE:
            label_txt = (f"Showing top {MAX_N_MATERIALS_IN_TABLE} of "
                         f"{n_filtered_results} materials - download csv for "
                         f"full results")
        else:
            label_txt = f"Showing all {n_filtered_results} results."

        label = html.Label(label_txt, className="has-margin-10")

        materials_table = materials_table_html(df, MAX_N_MATERIALS_IN_TABLE)
        materials_html = html.Div(
            children=[
                big_results_label_and_disclaimer,
                label,
                link,
                materials_table,
            ],
            className=common_results_container_style(),
        )
        return materials_html
Esempio n. 5
0
from matscholar_web.search.common import (
    big_label_and_disclaimer_html,
    common_results_container_style,
    no_results_html,
)
"""
Functions for defining the results container when materials summary is desired.

Please do not define callback logic in this file.
"""

MAX_N_MATERIALS_IN_TABLE = 100  # the maximum number of rows shown in the table
MAX_N_DOIS_FOR_VIEWING = 5  # The maximum number of viewable DOIs on this page.

big_results_label_and_disclaimer = big_label_and_disclaimer_html("materials")
materials_no_results_html = no_results_html(
    pre_label=big_results_label_and_disclaimer)


def materials_results_html(entity_query, raw_text):
    """
    Get the html block for materials summaru from the Rester-compatible
    entity query and text.

    Args:
        entity_query (dict): The entity query, in Rester-compatible format.
        raw_text (str, None): Any raw text to search for.

    Returns:
        (dash_html_components.Div): The materials summary html block.
    """
    results = rester.materials_search(entity_query,
Esempio n. 6
0
from matscholar_web.search.common import (
    big_label_and_disclaimer_html,
    common_results_container_style,
    no_results_html,
)
"""
Functions for defining the results container when entity results are desired.

Please do not define callback logic in this file.
"""

# Maximum number of rows shown for each entity table. 10 usually looks good.
MAX_N_ROWS_FOR_EACH_ENTITY_TABLE = 10

big_label_and_disclaimer = big_label_and_disclaimer_html("entities")
entities_no_results_html = no_results_html(pre_label=big_label_and_disclaimer)


def entities_results_html(entity_query, raw_text):
    """
    Get the html block for entities results from the Rester-compatible
    entity query and text.

    Args:
        entity_query (dict): The entity query, in Rester-compatible format.
        raw_text (str, None): Any raw text to search for.

    Returns:
        (dash_html_components.Div): The entities results html block.

    """