Ejemplo n.º 1
0
    def find_mathml(self,docid,position):
        """
        Find a specific math expression
        :param docid: document number or -1 (to read query)
        :type  docid: int
        :param position: relative number of math expr within document
        :type  position: int

        :return MathML or None
        :rtype: string
        """
        if docid < 0: # hack to allow for reading queries instead
            (ext,content) = self.read_doc_file(self.queries)
        else:
            (ext,content) = self.read_doc_file(self.find_doc_file(docid))
        if ext == '.tex':
            if position > 0:
                print("Warning: .tex documents have only one expression; position %i ignored\n"%position)
            mathml = LatexToMathML.convert_to_mathml(content)
        else:
            maths = MathExtractor.math_tokens(content)
            if position >= len(maths):
                print("Cannot find MathML expression: position %i too large"%position)
                return None
            mathml = maths[position]
        return(mathml)
Ejemplo n.º 2
0
    def find_mathml(self,docid,position):
        """
        Find a specific math expression
        :param docid: document number or -1 (to read query)
        :type  docid: int
        :param position: relative number of math expr within document
        :type  position: int

        :return MathML or None
        :rtype: string
        """
        if docid < 0: # hack to allow for reading queries instead
            (ext,content) = self.read_doc_file(self.queries)
        else:
            (ext,content) = self.read_doc_file(self.find_doc_file(docid))
        if ext == '.tex':
            if position > 0:
                print("Warning: .tex documents have only one expression; position %i ignored\n"%position)
            mathml = LatexToMathML.convert_to_mathml(content)
        else:
            maths = MathExtractor.math_tokens(content)
            if position >= len(maths):
                print("Cannot find MathML expression: position %i too large"%position)
                return None
            mathml = maths[position]
        return(mathml)