Esempio n. 1
0
    def update_from_unit(self, translation, unit, pos, template=None):
        """
        Process translation toolkit unit and stores/updates database entry.
        """
        if template is None:
            src = get_source(unit)
            ctx = get_context(unit)
        else:
            src = get_target(template)
            ctx = get_context(template)
        checksum = msg_checksum(src, ctx)

        # Try getting existing unit
        from weblate.trans.models import Unit

        dbunit = None
        try:
            dbunit = self.get(translation=translation, checksum=checksum)
            force = False
        except Unit.MultipleObjectsReturned:
            # Some inconsistency (possibly race condition), try to recover
            self.filter(translation=translation, checksum=checksum).delete()
        except Unit.DoesNotExist:
            pass

        # Create unit if it does not exist
        if dbunit is None:
            dbunit = Unit(translation=translation, checksum=checksum, source=src, context=ctx)
            force = True

        # Update all details
        dbunit.update_from_unit(unit, pos, force, template)

        # Return result
        return dbunit, force
Esempio n. 2
0
    def test_get_operon(self):
        records = [
            GeneInterval(
                268, 469,
                ('MVLRQLSRQASVRVSKTWTGTKRRAQRIFIFILELLLEFCRGEDSVDGKNKSTTALPA'
                 'VKDSVKDS'), 1
            ),
            GeneInterval(
                504, 1560,
                ('MGAALALLGDLVASVSEAAAATGFSVAEIAAGEAAAAIEVQIAS'
                 'LATVEGITSTSEAIAAIGLTPQTYAVIAGAPGAIAGFAALIQTVTGISSLAQVGYRFF'
                 'SDWDHKVSTVGLYQQSGMALELFNPDEYYDILFPGVNTFVNNIQYLDPRHWGPSLFAT'
                 'ISQALWHVIRDDIPAITSQELQRRTERFFRDSLARFLEETTWTIVNAPVNFYNYIQDY'
                 'YSNLSPIRPSMVRQVAEREGTQVNFGHTYRIDDADSIQEVTQRMELRNKENVHSGEFI'
                 'EKTIAPGGANQRTAPQWMLPLLLGLYGTVTPALEAYEDGPNQKKRRVSRGSSQKAKGT'
                 'RASAKTTNKRRSRSSRS'), 1
            ),
            GeneInterval(
                861, 1560,
                ('MALELFNPDEYYDILFPGVNTFVNNIQYLDPRHWGPSLFATISQ'
                 'ALWHVIRDDIPAITSQELQRRTERFFRDSLARFLEETTWTIVNAPVNFYNYIQDYYSN'
                 'LSPIRPSMVRQVAEREGTQVNFGHTYRIDDADSIQEVTQRMELRNKENVHSGEFIEKT'
                 'IAPGGANQRTAPQWMLPLLLGLYGTVTPALEAYEDGPNQKKRRVSRGSSQKAKGTRAS'
                 'AKTTNKRRSRSSRS'), 1
            )
        ]
        operon = get_context(records, 0, 100)
        self.assertGreater(len(operon), 0)

        operon = get_context(records, 1, 100)
        self.assertGreater(len(operon), 0)
Esempio n. 3
0
def reply_for_query(fb_id, fb_text):
    distance = []
    if util.get_context(fb_id) is None:
        intent, parameter = apiai_query(fb_text)

        if intent == General_Talk:
            text1 = quick_reply_template_class("text",
                                               title="need medicine",
                                               image_url="",
                                               payload="medicine.need")
            text2 = quick_reply_template_class("text",
                                               title="update medicine",
                                               image_url="",
                                               payload="medicine.update")
            data = text_template(
                fb_id,
                "How can i help you",
                quick_reply=True,
                type=[quick_reply_type.text, quick_reply_type.text],
                data=[text1.__dict__, text2.__dict__])
        #     TODO:set the context to need or update medicine
        elif intent == Query_medicine:
            if not parameter.get("drug", None) is None:
                drug = parameter["drug"]
                brand = drug
            else:
                brand = parameter["brand"]

            # TODO GET BRAND NAME IF DRUGNAME IS GIVEN
            if not parameter.get("number", None) is None:
                quantity = parameter["number"]

                generic_data = query_medicine_responce_builder(
                    fb_id, brand, quantity)
                data = generic_data.__dict__
            else:
                # TODO Handle case when user texts only with medicine name
                util.create_context(fb_id, "MISSING_QTY", (brand))
                data = text_template(fb_id,
                                     "How mcuh quantity you need",
                                     quick_reply=False)
        else:
            data = text_template(fb_id,
                                 "this feature is yet to be implimented",
                                 quick_reply=False)

    elif util.get_context(fb_id) == "MISSING_QTY":
        brand = util.get_context_data(fb_id)
        util.remove_context(fb_id)
        quantity = fb_text
        generic_data = query_medicine_responce_builder(fb_id, brand, quantity)
        data = generic_data.__dict__

    reply(data)
Esempio n. 4
0
    def test_boundaries(self):
        res = get_context(self.genes, 0, window_size=3)
        g1 = GeneInterval(1, 2, 'G', 1)
        n1 = GeneInterval(3, 4, 'H', 1)
        n2 = GeneInterval(4, 5, 'I', 1)

        self.assertNotIn(g1, res)
        self.assertIn(n1, res)
        self.assertIn(n2, res)

        res = get_context(self.genes, 5, window_size=3)
        n1 = GeneInterval(13, 14, 'J', -1)
        g1 = GeneInterval(15, 16, 'L', -1)

        self.assertNotIn(g1, res)
        self.assertIn(n1, res)
Esempio n. 5
0
    def test_context(self):
        res = get_context(self.genes, 1, window_size=3)
        exp = GeneInterval(1, 2, 'G', 1)
        self.assertEqual(res[0], exp)

        exp = GeneInterval(4, 5, 'I', 1)
        self.assertEqual(res[1], exp)
Esempio n. 6
0
 def draw_gene(i, d):
     if d <= self.within_prob:
         # draw operon
         operon = get_context(gis, i, self.window_size)
         j = np.random.randint(0, len(operon))
         return gis[i], operon[j]
     else:
         # draw outside operon
         j = draw_exclusive(len(gis), i)
         return gis[i], gis[j]
Esempio n. 7
0
    def update_from_unit(self, translation, unit, pos, template=None):
        '''
        Process translation toolkit unit and stores/updates database entry.
        '''
        if template is None:
            src = get_source(unit)
            ctx = get_context(unit)
        else:
            src = get_target(template)
            ctx = get_context(template)
        checksum = msg_checksum(src, ctx)

        # Try getting existing unit
        from weblate.trans.models import Unit
        dbunit = None
        try:
            dbunit = self.get(translation=translation, checksum=checksum)
            force = False
        except Unit.MultipleObjectsReturned:
            # Some inconsistency (possibly race condition), try to recover
            self.filter(translation=translation, checksum=checksum).delete()
        except Unit.DoesNotExist:
            pass

        # Create unit if it does not exist
        if dbunit is None:
            dbunit = Unit(translation=translation,
                          checksum=checksum,
                          source=src,
                          context=ctx)
            force = True

        # Update all details
        dbunit.update_from_unit(unit, pos, force, template)

        # Return result
        return dbunit, force
Esempio n. 8
0
 def wrapper(*args, **kwargs):
     kwargs[self.keyword] = get_context(kwargs["rpc"])
     rv = callback(*args, **kwargs)
     return rv
Esempio n. 9
0
File: Q4.py Progetto: Zzbra/TAL
from util import get_context
from util import remove_ponctuation

with open("corpus_modifié.txt") as f:
    content = f.readlines()

for i in range(len(content)):
    if len(content[i].split("\t")) > 2:
        replace = content[i].split("\t")
        replace[1] = remove_ponctuation(replace[1])
        content[i] = "\t".join(replace)
        print(content[i])

output = open("corpus_prep.data", "w")
for i in range(len(content)):
    output_line = ""
    input_line = content[i].split("\t")
    # print(input_line)
    if len(input_line) > 2:
        if input_line[4] == "hyp\n":
            context = get_context(i, content)
            output_line += str(i+1) + " , " + context[0] + " , " \
                           + input_line[1] + " , " + context[1] + " , " + input_line[3] + " ."
            output.write(output_line + "\n")