Example #1
0
def do_unification((mt_str_query, mt_str_dt)):
    mt_xml_query = etree.fromstring(mt_str_query)

    m_repr = get_math_repr(mt_str_dt)
    mt_xml_dt = etree.fromstring(m_repr)
    mt_xml_b = extract_mathmlcontent_from_dataset(mt_xml_dt)
    if mt_xml_b is None: return mt_str_dt, False
    mt_xml_b.tag = "semantics"

    u = Unification()
#    print etree.tostring(mt_xml_query)
#    print etree.tostring(mt_xml_b)
    matchlevel, isunify = u.align(mt_str_query, etree.tostring(mt_xml_b))
    return mt_str_dt, isunify
Example #2
0
    def __unify(self, mt_xml_query, mt_xml_result):
        ann_xml_query = self.__extract_mathmlcontent(mt_xml_query)

        ann_xml_query.tag = "semantics"
        mt_str_query = etree.tostring(ann_xml_query)

        ann_xml_res = self.__extract_mathmlcontent(mt_xml_result)
        if ann_xml_res is None: return False
        ann_xml_res.tag = "semantics"
        mt_str_res = etree.tostring(ann_xml_res)

        u = Unification()
        matchlevel, isunify = u.align(mt_str_query, mt_str_res)
        return isunify
Example #3
0
def do_unification((mt_str_query, mt_str_dt)):
    mt_xml_query = etree.fromstring(mt_str_query)

    m_repr = get_math_repr(mt_str_dt)
    mt_xml_dt = etree.fromstring(m_repr)
    mt_xml_b = extract_mathmlcontent_from_dataset(mt_xml_dt)
    if mt_xml_b is None: return mt_str_dt, False
    mt_xml_b.tag = "semantics"

    u = Unification()
    #    print etree.tostring(mt_xml_query)
    #    print etree.tostring(mt_xml_b)
    matchlevel, isunify = u.align(mt_str_query, etree.tostring(mt_xml_b))
    return mt_str_dt, isunify
Example #4
0
    def __unify(self, mt_xml_query, mt_xml_result):
        ann_xml_query       = self.__extract_mathmlcontent(mt_xml_query)

        ann_xml_query.tag   = "semantics"
        mt_str_query        = etree.tostring(ann_xml_query)

        ann_xml_res         = self.__extract_mathmlcontent(mt_xml_result)
        if ann_xml_res is None: return False
        ann_xml_res.tag     = "semantics"
        mt_str_res          = etree.tostring(ann_xml_res)

        u = Unification()
        matchlevel, isunify = u.align(mt_str_query, mt_str_res)
        return isunify
Example #5
0
    def on_validate(self):
        unification = Unification([])
        self.terms_table_holder.setPlainText('')

        for left_input, right_input in zip(self.ops_left_inputs,
                                           self.ops_right_inputs):
            if not left_input.text() or not right_input.text():
                self.terms_table_holder.insertPlainText(
                    '---------------------------------------------------\n' +
                    'Attention!! Une partie vide est détectée, donc celle l\'équation est ignorée.\n'
                    + '---------------------------------------------------\n')
                continue

            liste_gauche = Analyse.analyse_lexical(left_input.text())
            liste_droite = Analyse.analyse_lexical(right_input.text())

            liste_gauche = Analyse.termes_separateur(liste_gauche)
            liste_droite = Analyse.termes_separateur(liste_droite)

            liste_gauche = Analyse.analyse_syntaxique(liste_gauche)
            liste_droite = Analyse.analyse_syntaxique(liste_droite)

            if len(liste_gauche) != len(liste_droite):
                self.terms_table_holder.insertPlainText(
                    '---------------------------------------------------\n' +
                    'Attention!! La partie gauche et partie droite n\'avons pas le même nombre des termes'
                    + ', donc le nombre minimum est gardé.\n' +
                    '---------------------------------------------------\n')

            liste_min = min(len(liste_gauche), len(liste_droite))

            for gauche, droite in zip(liste_gauche[:liste_min],
                                      liste_droite[:liste_min]):
                equation = Equation(gauche, droite)
                unification.equations.append(equation)

            self.terms_table_holder.insertPlainText(
                '---------------------------------------------------\n'
                '1er partie: ----------\n' +
                (Terme.terms_table(liste_gauche) or '<Pas des termes>\n') +
                '2eme partie: ----------\n' +
                (Terme.terms_table(liste_droite) or '<Pas des termes>\n'))

        self.unification_holder.setPlainText(unification.moteur_unification())
Example #6
0
        ann_p = ann.getparent()
        ann_p.remove(ann)
    for sem in f.xpath(".//*[local-name() = 'semantics']"):
        queries[qid].append(sem)

#play th judgment pool
pool_address = "NTCIR11_Math-qrels.dat"
for ln in open(pool_address).readlines():
    cells = ln.strip().split()
    qid = cells[0]
    qid = qid[qid.rindex("-") + 1:]

    pid = cells[2]
    rel = int(cells[3])

    mathml_flname = "%s_%s" % (qid, pid)
    mathml_address = path.join("dataset_small", mathml_flname)

    for math_ln in open(mathml_address).readlines():
        mathcells = math_ln.strip().split("\t")
        mathstring = "\t".join(mathcells[3:])

        mt_xml_b = etree.fromstring(mathstring)

        for mt_xml_a in queries[qid]:
            u = Unification()
            isunify = u.align(mt_xml_a, mt_xml_b)
            print isunify
        break
    break
from histogram_gray import HistogramGray
from histogram_color import HistogramColor
from arithmetic_color import ArithmeticColor
from arithmetic_gray import ArithmeticGray
from geometric import Geometric
from morpho_bin import MorphoBin
from morpho_gray import MorphoGray

from filter import Filter

zad1 = "img/zad1/"
zad5 = "img/zad5/"
zad6 = "img/zad6/"
zad9 = "img/zad9/"

ex1 = Unification(zad1 + "pirate_gray.tiff", zad1 + "gentelman_gray.tiff")
ex1.geometricGray(show=True)
ex1.rasterGray(show=True)
ex1.load(zad1 + "peppers_color.tiff", zad1 + "lena_color.tiff")
ex1.geometricColor(show=True)
ex1.rasterColor(show=True)
# ex1.load(zad1 + "boat_gray.tiff", zad1 + "clock_gray.tiff")
# ex1.geometricGray(show=True)
# ex1.rasterGray(show=True)
# ex1.load(zad1 + "mandrill_color.tiff", zad1 + "candy_color.tiff")
# ex1.geometricColor(show=True)
# ex1.rasterColor(show=True)
# ##
##

ex2a = ArithmeticGray(image1Path="../../Resources/Gray/Zegarek.tiff",
        ann_p.remove(ann)
    for sem in f.xpath(".//*[local-name() = 'semantics']"):
        queries[qid].append(sem)

#play th judgment pool
pool_address = "NTCIR11_Math-qrels.dat"
for ln in open(pool_address).readlines():
    cells = ln.strip().split()
    qid = cells[0]
    qid = qid[qid.rindex("-")+1:]

    pid = cells[2]
    rel = int(cells[3])
   
    mathml_flname = "%s_%s" % (qid, pid)
    mathml_address= path.join("dataset_small", mathml_flname)

    for math_ln in open(mathml_address).readlines():
        mathcells = math_ln.strip().split("\t")
        mathstring= "\t".join(mathcells[3:])

        mt_xml_b = etree.fromstring(mathstring)
        
        for mt_xml_a in queries[qid]:
            u = Unification()
            isunify = u.align(mt_xml_a, mt_xml_b)
            print isunify
        break
    break

                <ci>normal-[</ci>
                <csymbol>X</csymbol>
                <geq/>
                <csymbol>t</csymbol>
                <ci>normal-]</ci>
              </cerror>
              <leq />
              <apply>
                <divide/>
                <apply >
                  <times/>
                  <ci>E</ci>
                  <qvar name="X"/>
                </apply>
                <qvar name="t"/>
              </apply>
            </cerror>
        </semantics>
"""

u = Unification()

#test alignments
mt_xml_a = etree.fromstring(s1)
mt_xml_b = etree.fromstring(s2)
alignments = u.align(mt_xml_a, mt_xml_b)
print alignments
#for k, v in alignments.iteritems():
#    print etree.tostring(k)
#    print [etree.tostring(val) for val in v]
                <ci>normal-[</ci>
                <csymbol>X</csymbol>
                <geq/>
                <csymbol>t</csymbol>
                <ci>normal-]</ci>
              </cerror>
              <leq />
              <apply>
                <divide/>
                <apply >
                  <times/>
                  <ci>E</ci>
                  <qvar name="X"/>
                </apply>
                <qvar name="t"/>
              </apply>
            </cerror>
        </semantics>
"""

u = Unification()

# test alignments
mt_xml_a = etree.fromstring(s1)
mt_xml_b = etree.fromstring(s2)
alignments = u.align(mt_xml_a, mt_xml_b)
print alignments
# for k, v in alignments.iteritems():
#    print etree.tostring(k)
#    print [etree.tostring(val) for val in v]