def serve_layout(doi="none", tokens=testTokens[0]):
    return html.Div([
        dmi.AnnotationContainer(doi=doi,
                                tokens=tokens,
                                labels=testLabels,
                                passiveLabels=[],
                                className="testClass",
                                id="annotation_container",
                                selectedValue=None),
        dmi.DropdownCreatable(
            options=[{
                'value': '',
                'label': 'material:'
            }, {
                'value': '',
                'label': 'property:'
            }, {
                'value': '',
                'label': 'application:'
            }],
            multi=True,
            id="tags_selector",
            placeholder="Add filters...",
            promptText="Add filter ",
            value=None,
        ),
        html.Div("doi is " + doi, id="test_output"),
        html.Div(html.Button("Confirm", id="annotate_confirm"))
    ])
Exemple #2
0
def serve_abstract(db,
                   user_key,
                   empty=False,
                   show_labels=None,
                   doi=None,
                   past_tokens=None):
    """Returns a random abstract and refreshes annotation options"""
    if empty:
        tokens = []
        existing_labels = []
    else:
        builder = AnnotationBuilder(local=True)
        # get a random paragraph
        random_abstract = builder.get_abstract(good_ones=True, doi=doi)
        doi = random_abstract['doi']
        # tokenize and get initial annotation
        cems = False
        if show_labels is not None and "MAT" in show_labels:
            cems = True
        tokens, existing_labels = builder.get_tokens(random_abstract, user_key, cems)
        if past_tokens is not None:
            tokens = past_tokens

    # labels for token-by-token annotation
    labels = AnnotationBuilder.LABELS

    macro_display = "none"
    passive_labels = []
    if show_labels is not None:
        passive_labels = [pl for pl in labels if pl["value"] in existing_labels and pl["value"] not in show_labels]
        labels = [label for label in labels if label["value"] in show_labels]
        if "application" in show_labels:
            macro_display = "block"

    return [
        html.Div([
            html.Span("doi: "), html.A(
                doi,
                href="https://doi.org/" + str(doi),
                target="_blank",
                id="doi_container")],
            className="row", style={"paddingBottom": "10px"}),
        dmi.AnnotationContainer(
            doi=doi,
            tokens=tokens,
            labels=labels,
            passiveLabels=passive_labels,
            className="annotation-container",
            selectedValue=labels[0]['value'],
            id="annotation_container"
        ),
        html.Div(serve_macro_annotation(db, macro_display), id="macro_annotation_container"),
        html.Div("", className="row instructions", id="annotation_instructions"),
        html.Div(serve_buttons(), id="buttons_container", className="row")
    ]
Exemple #3
0
def serve_abstract(user_key, doi=None):
    """Returns a random abstract and refreshes annotation options"""
    builder = AnnotationBuilder(local=False)
    diff_tokens, message = builder.get_diff_tokens(doi=doi, user=user_key)
    if diff_tokens is not None:
        return [
            html.Div([
                html.Span("doi: "),
                html.A(doi,
                       href="https://doi.org/" + str(doi),
                       target="_blank",
                       id="doi_container")
            ],
                     className="row",
                     style={"paddingBottom": "10px"}),
            dmi.AnnotationContainer(doi=doi,
                                    tokens=diff_tokens,
                                    labels=[],
                                    className="annotation-container",
                                    selectedValue=None,
                                    id="annotation_container"),
        ]
    return message