Пример #1
0
    def test_markCriticalTemperature_relative_critical_temperature_3(self):
        input = "The material BaClE2 has Tc at 30K higher than 77K."

        spans = [("BaClE2", "<material>"), ("<tc>", "<tc>"),
                 ("30K", "<tcValue>")]

        target = CriticalTemperatureClassifier()
        doc = prepare_doc(input, spans)
        doc2 = target.process_doc(doc)

        tcValues = [
            entity for entity in filter(
                lambda w: w.ent_type_ in ['<tcValue>'] and w._.linkable is
                True, doc2)
        ]

        assert len(tcValues) == 0
Пример #2
0
    def test_markCriticalTemperature_simple_3(self):
        input = "We are explaining some important notions. The material BaClE2 superconducts at 30K. What about going for a beer?"

        spans = [("<tc>", "<tc>"), ("BaClE2", "<material>"),
                 ("30K", "<tcValue>")]

        target = CriticalTemperatureClassifier()
        doc = prepare_doc(input, spans)
        doc2 = target.process_doc(doc)

        tcValues = [
            entity for entity in filter(
                lambda w: w.ent_type_ in ['<tcValue>'] and w._.linkable is
                True, doc2)
        ]

        assert len(tcValues) == 1
        assert tcValues[0].text == "30K"
Пример #3
0
    def test_markCriticalTemperature_simple_2(self):
        input = "The material BaClE2 superconducts at 30K."

        spans = [("BaClE2", "<material>"), ("superconducts", "<tc>"),
                 ("30K", "<tcValue>")]

        target = CriticalTemperatureClassifier()
        doc = prepare_doc(input, spans)
        doc2 = target.process_doc(doc)

        tcValues = [
            entity for entity in filter(
                lambda w: w.ent_type_ in ['<tcValue>'] and w._.linkable is
                True, doc2)
        ]

        assert len(tcValues) == 1
        assert tcValues[0].text == "30K"
Пример #4
0
    def test_markCriticalTemperature_2(self):
        input = "(Color online) Effect of electron irradiation on the low-temperature penetration depth ∆λ of two " \
                "samples of BaFe2(As1−xPx)2: (a) Tc0 = 28 K and (b) Tc0 = 29 K."

        spans = [("BaFe2(As1−xPx)2", "<material>"), ("Tc0", "<tc>"),
                 ("28 K", "<tcValue>"), ("Tc0", "<tc>"), ("29 K", "<tcValue>")]

        target = CriticalTemperatureClassifier()
        doc = prepare_doc(input, spans)
        doc2 = target.process_doc(doc)

        tcValues = [
            entity for entity in filter(
                lambda w: w.ent_type_ in ['<tcValue>'] and w._.linkable is
                True, doc2)
        ]

        assert len(tcValues) == 2
Пример #5
0
    def test_markCriticalTemperature_1(self):
        input = "We also plot in values of U 0 obtained from flux-creep in a BaFe 2−x Ni x As 2 crystal with " \
                "similar T c for H c-axis at T = 8 K and for H ab-planes at T = 13 K."

        spans = [("BaFe 2−x Ni x As 2 crystal", "<material>"), ("T c", "<tc>"),
                 ("8 K", "<tcValue>"), ("13 K", "<tcValue>")]

        target = CriticalTemperatureClassifier()
        doc = prepare_doc(input, spans)
        doc2 = target.process_doc(doc)

        tcValues = [
            entity for entity in filter(
                lambda w: w.ent_type_ in ['<tcValue>'] and w._.linkable is
                True, doc2)
        ]

        assert len(tcValues) == 0
Пример #6
0
    def test_markCriticalTemperature_relative_critical_temperature_2(self):
        input = "The critical temperature T C = 4.7 K discovered for La 3 Ir 2 Ge 2 in this work is by about 1.2 K " \
                "higher than that found for La 3 Rh 2 Ge 2 ."

        spans = [("critical temperature", "<tc>"), ("T C", "<tc>"),
                 ("4.7 K", "<tcValue>"), ("La 3 Ir 2 Ge 2", "<material>"),
                 ("La 3 Rh 2 Ge 2", "<material>")]

        target = CriticalTemperatureClassifier()
        doc = prepare_doc(input, spans)
        doc2 = target.process_doc(doc)

        tcValues = [
            entity for entity in filter(
                lambda w: w.ent_type_ in ['<tcValue>'] and w._.linkable is
                True, doc2)
        ]

        assert len(tcValues) == 1
        assert tcValues[0].text == "4.7 K"
Пример #7
0
    def test_markCriticalTemperature_relative_critical_temperature(self):
        input = "The R versus T curves (figure 2(c) for samples B1 and B2 (with 6 wt% Ag) show that the HIP process " \
                "increases T c by 0.8 K and reduces the resistance in the normal state by about 10%."

        spans = [
            ("B1", "<material>"),
            ("B2 (with 6 wt% Ag)", "<material>"),
            ("0.8 K", "<tcValue>"),
        ]

        target = CriticalTemperatureClassifier()
        doc = prepare_doc(input, spans)
        doc2 = target.process_doc(doc)

        tcValues = [
            entity for entity in filter(
                lambda w: w.ent_type_ in ['<tcValue>'] and w._.linkable is
                True, doc2)
        ]

        assert len(tcValues) == 0
Пример #8
0
    def test_mark_temperatures_process(self):
        text = "The LaFe0.2 Sr 0.4 was discovered to be superconducting at 3K applying a pressure of 5Gpa."
        input_spans = [("LaFe0.2 Sr 0.4", "<material>"),
                       ("superconducting", "<tc>"), ("3K", "<tcValue>"),
                       ("5Gpa", "<pressure>")]
        tokens, spans = get_tokens_and_spans(text, input_spans)

        paragraph = {"text": text, "spans": spans, "tokens": tokens}

        target = CriticalTemperatureClassifier()

        spans[0]['linkable'] = True
        process_paragraph = target.mark_temperatures_paragraph(paragraph)

        linkable_spans = [
            span for span in process_paragraph['spans']
            if span['linkable'] is True
        ]

        assert len(linkable_spans) == 2
        assert process_paragraph['spans'][0]['linkable'] is True
        assert process_paragraph['spans'][2]['linkable'] is True
Пример #9
0
    def test_markCriticalTemperature_3(self):
        input = "It is also worth noticing that the T C of this structure is slightly lower (about 5 K lower) than " \
                "the T C for the 2×7 superlattice where the two BCO/CCO interfaces are far apart (seven unit " \
                "cells of CCO) and no sizeable intralayer interaction is expected.It is also worth noticing that " \
                "the T C of this structure is slightly lower (about 5 K lower) than the T C for the 2×7 " \
                "superlattice where the two BCO/CCO interfaces are far apart (seven unit cells of CCO) and no " \
                "sizeable intralayer interaction is expected."

        spans = [("BCO/CCO", "<material>"), ("CCO)", "<material>"),
                 ("T C", "<tc>"), ("5 K", "<tcValue>")]

        target = CriticalTemperatureClassifier()
        doc = prepare_doc(input, spans)
        doc2 = target.process_doc(doc)

        tcValues = [
            entity for entity in filter(
                lambda w: w.ent_type_ in ['<tcValue>'] and w._.linkable is
                True, doc2)
        ]

        assert len(tcValues) == 0
Пример #10
0
    def test_markCriticalTemperature_complex_case(self):
        input = "Tc varies from 2.7 K in CsFe2As2 to 38 K in A1−xKxFe2As2 (A = Ba, Sr). Meanwhile, superconductivity " \
                "could also be induced in the parent phase by high pressure or by replacing some of the Fe by Co. " \
                "More excitingly, large single crystals could be obtained by the Sn flux method in this family to " \
                "study the rather low melting temperature and the intermetallic characteristics."

        spans = [("Tc", "<tc>"), ("2.7 K", "<tcValue>"),
                 ("CsFe2As2", "<material>"), ("38 K", "<tcValue>"),
                 ("A1−xKxFe2As2", "<material>")]

        target = CriticalTemperatureClassifier()
        doc = prepare_doc(input, spans)
        doc2 = target.process_doc(doc)

        tcValues = [
            entity for entity in filter(
                lambda w: w.ent_type_ in ['<tcValue>'] and w._.linkable is
                True, doc2)
        ]

        assert len(tcValues) == 1

        assert tcValues[0].text == "2.7 K"
Пример #11
0
    def test_markCriticalTemperature_respectively_1(self):
        input = "The T C values for YBCO + BSO2%, YBCO + BSO2% + YOA, and YBCO + BSO2% + YOB fi lms are 89.7 K, 86.7 K, and 89.7 K respectively"

        spans = [("T C", "<tc>"), ("YBCO + BSO2%", "<material>"),
                 ("YBCO + BSO2% + YOA", "<material>"),
                 ("YBCO + BSO2% + YOB", "<material>"), ("89.7 K", "<tcValue>"),
                 ("86.7 K", "<tcValue>"), ("89.7 K", "<tcValue>")]

        target = CriticalTemperatureClassifier()
        doc = prepare_doc(input, spans)
        doc2 = target.process_doc(doc)

        tcValues = [
            entity for entity in filter(
                lambda w: w.ent_type_ in ['<tcValue>'] and w._.linkable is
                True, doc2)
        ]

        assert len(tcValues) == 3

        assert tcValues[0].text == "89.7 K"
        assert tcValues[1].text == "86.7 K"
        assert tcValues[2].text == "89.7 K"
Пример #12
0
 def __init__(self):
     self.linker_material_tc = RuleBasedLinker(source="<tcValue>",
                                               destination="<material>")
     self.linker_tc_pressure = RuleBasedLinker(source="<pressure>",
                                               destination="<tcValue>")
     self.temperature_classifier = CriticalTemperatureClassifier()
Пример #13
0
class Service(object):
    def __init__(self):
        self.linker_material_tc = RuleBasedLinker(source="<tcValue>",
                                                  destination="<material>")
        self.linker_tc_pressure = RuleBasedLinker(source="<pressure>",
                                                  destination="<tcValue>")
        self.temperature_classifier = CriticalTemperatureClassifier()

    def info(self):
        returnText = "Python utilities wrapper as a micro-service."
        return returnText

    def mark_critical_temperature(self):
        input_raw = request.forms.get("input")

        return self.temperature_classifier.mark_temperatures_paragraph_json(
            input_raw)

    def create_links(self):
        input_raw = request.forms.get("input")
        paragraph_input = json.loads(input_raw)

        material_tc_linked = self.linker_material_tc.process_paragraph(
            paragraph_input)
        tc_pressure_linked = self.linker_tc_pressure.process_paragraph(
            paragraph_input)

        spans_map = {}
        for paragraphs in tc_pressure_linked:
            spans = paragraphs['spans'] if 'spans' in paragraphs else []
            for span in spans:
                if 'links' in span:
                    non_crf_links = list(
                        filter(lambda w: w['type'] != "crf", span['links']))

                    if len(non_crf_links) > 0:
                        span['links'] = non_crf_links
                        spans_map[span['id']] = span

        # for span in paragraphs['spans'] if 'spans' in paragraphs else []:
        #     if 'links' in span and len(span['links']) > 0:
        #         links = span['links']
        #         if span['id'] in spans_map:
        #             spans_map[span['id']].extend(list(filter(lambda w: w['type'] != "crf", links)))
        #         else:
        #             spans_map[span['id']] = list(filter(lambda w: w['type'] != "crf", links))
        # span['id'] in spans_map and 'links' in spans_map[span['id']]

        for paragraphs in material_tc_linked:
            for span in paragraphs['spans'] if 'spans' in paragraphs else []:
                if span['id'] in spans_map and 'links' in spans_map[
                        span['id']]:
                    links_list = spans_map[span['id']]['links']
                    if 'links' in span:
                        span['links'].extend(links_list)
                    else:
                        span['links'] = links_list

        # for paragraphs in material_tc_linked:
        #     for span in paragraphs['spans'] if 'spans' in paragraphs else []:
        #         if span['id'] in spans_map:
        #             if 'links' in span:
        #                 span['links'].extend(spans_map[span['id']])
        #             else:
        #                 span['links'] = spans_map[span['id']]
        # for paragraphs in material_tc_linked:
        #     material_tc_linked['relationships'].extends(tc_pressure_linked['relationships'])

        return json.dumps(material_tc_linked)

    def resolve_class(self):
        formula_raw = request.forms.get("input")
        classes = MaterialParserWrapper().formula_to_classes(formula_raw)

        return json.dumps(list(classes.keys()))

    def process(self):
        input_raw = request.forms.get("input")
        input_json = json.loads(input_raw)
        paragraph_with_marked_tc = self.linker_material_tc.mark_temperatures_paragraph(
            input_json)

        material_tc_linked = self.linker_material_tc.process_paragraph_json(
            paragraph_with_marked_tc)
        return self.linker_tc_pressure.process_paragraph_json(
            material_tc_linked)