예제 #1
0
    def get_dep_graph(self, maths, matching_method):
        '''
        input: file from math_new
        output: 
            1. edges: {gumid1:[(gumid2, linktype)]} --> component list
            2. gumidmappings: {gmid:gumid}
        '''
        #useful utilities classes
        n_arxiv         = norm_arxiv()
        n_attribute     = norm_attribute()
        n_mrow          = norm_mrow(self.__dtd)
        n_outer_fence   = norm_outer_fence()
        n_tag           = norm_tag(self.__dtd)
        n_splitter      = norm_splitter(self.__dtd, self.__relation_fl)
        u               = utils()
        depgraph        = depgraph_heur(matching_method)

        #enumerate if there is no id in the <math> tag
        mts = OrderedDict()
            
        #for xhtml, enumerate mathtag; for xml, enumerate expressiontag; for math_new, enumerate the lines
        for gmid, mt in maths.iteritems():
            #replace <m:math> with <math>
            mt_string_initial = n_arxiv.remove_math_prefix(etree.tostring(mt))

            #remove annotation, attributes, and finally get rid the <math> tag
            mt_string_formatted = n_arxiv.remove_annotation(etree.parse(StringIO(self.__dtd + mt_string_initial)).getroot())
            mt_string_formatted = n_attribute.normalize(mt_string_formatted)

            #normalize mrow
            mt_string_formatted = n_mrow.normalize(mt_string_formatted) 

            #remove fences
            mt_string_formatted = etree.tostring(n_outer_fence.remove_outer_fence(etree.parse(StringIO(self.__dtd + mt_string_formatted)).getroot()))[6:-7]

            #expand maths (normalize tags and/or case)
            expanded = n_tag.normalize_tags('<math>%s</math>' % mt_string_formatted)

            if len(expanded) > 0:
                expanded[-1] = n_mrow.normalize('<math>%s</math>' % expanded[-1])[6:-7]
                expanded.extend([etree.tostring(n_outer_fence.remove_outer_fence(etree.parse(StringIO(self.__dtd + '<math>%s</math>' % exp)).getroot()))[6:-7] for exp in expanded])
            else:
                expanded = [mt_string_formatted]

            mts[gmid] = expanded

            #split around the equality and get the left side subexpressions
            left_subexp = n_splitter.split('<math>%s</math>' % expanded[-1])
            if left_subexp is None: continue

            left_subexp = n_mrow.normalize(left_subexp)[6:-7]
            if not u.is_empty_tag(left_subexp):
                expanded_left = n_tag.normalize_tags(left_subexp)
                expanded_left = [n_mrow.normalize('<math>%s</math>' % exp)[6:-7] for exp in expanded_left]

                mts[gmid].append(left_subexp)
                mts[gmid].extend(expanded_left)

            mts[gmid] = list(set(mts[gmid]))
        edges = depgraph.create_edges(mts)
        return edges
예제 #2
0
if __name__ == 'app.Controllers.PlantController':
    from ..Handlers.ResponseHandler import ResponseHandler
    from ..Handlers.QueryHandler import QueryHandler
    from ..utilities.validate import Validate
    from ..utilities.utils import utils
else:
    import sys
    sys.path.append('..')
    from utilities.utils import utils
    from utilities.validate import Validate
    from Handlers.QueryHandler import QueryHandler
    from Handlers.ResponseHandler import ResponseHandler

responserHandler = ResponseHandler()
Utils = utils()


class Plant():
    def __init__(self):
        self.id = ''
        self.name = ''
        self.date = ''
        self.photo = ''
        self.idGreen = ''

    def createPlant(self, plant):
        try:
            validate = Validate()

            validatePlant = validate.validateForm(
                form=plant, param=['id-estufa', 'nome-planta'])
예제 #3
0
 def __init__(self, driver):
     super(basepage, self).__init__(driver)
     self.driver = driver
     self.util = utils()