Search in sources :

Example 1 with TeXParser

use of org.matheclipse.core.form.tex.TeXParser in project symja_android_library by axkr.

the class Pods method parseInput.

/**
 * package private
 */
static IExpr parseInput(String inputStr, EvalEngine engine) {
    engine.setPackageMode(false);
    IExpr inExpr = F.NIL;
    // }
    if (!inExpr.isPresent()) {
        final FuzzyParser parser = new FuzzyParser(engine);
        try {
            inExpr = parser.parseFuzzyList(inputStr);
        } catch (SyntaxError serr) {
            // this includes syntax errors
            LOGGER.debug("Pods: FuzzyParser.parseFuzzyList() failed", serr);
            TeXParser texConverter = new TeXParser(engine);
            inExpr = texConverter.toExpression(inputStr);
        }
    }
    if (inExpr == S.$Aborted) {
        return F.NIL;
    }
    if (inExpr.isList() && inExpr.size() == 2) {
        inExpr = inExpr.first();
    }
    if (inExpr.isTimes() && !inExpr.isNumericFunction(true) && inExpr.argSize() <= 4) {
        if (((IAST) inExpr).isEvalFlagOn(IAST.TIMES_PARSED_IMPLICIT)) {
            inExpr = flattenTimes((IAST) inExpr).orElse(inExpr);
            IAST rest = ((IAST) inExpr).setAtClone(0, S.List);
            IASTAppendable specialFunction = F.NIL;
            String stemForm = getStemForm(rest.arg1().toString().toLowerCase());
            IExpr head = rest.head();
            if (stemForm != null) {
                head = STEM.getSymbol(stemForm);
                if (head != null) {
                    specialFunction = rest.setAtClone(0, head);
                    specialFunction.remove(1);
                }
            }
            if (!specialFunction.isPresent()) {
                stemForm = getStemForm(rest.last().toString().toLowerCase());
                if (stemForm != null) {
                    head = STEM.getSymbol(stemForm);
                    if (head != null) {
                        specialFunction = rest.setAtClone(0, head);
                        specialFunction.remove(rest.size() - 1);
                    }
                }
            }
            if (specialFunction.isPresent()) {
                if (head != null) {
                    if (head == S.UnitConvert) {
                        IExpr temp = unitConvert(engine, rest.rest());
                        if (temp.isPresent()) {
                            return temp;
                        }
                    } else {
                        int i = 1;
                        while (i < specialFunction.size()) {
                            String argStr = specialFunction.get(i).toString().toLowerCase();
                            if (argStr.equalsIgnoreCase("by") || argStr.equalsIgnoreCase("for")) {
                                specialFunction.remove(i);
                                continue;
                            }
                            i++;
                        }
                        return specialFunction;
                    }
                }
            }
            if (rest.arg1().toString().equalsIgnoreCase("convert")) {
                rest = inExpr.rest();
            }
            if (rest.argSize() > 2) {
                rest = rest.removeIf(x -> x.toString().equals("in"));
            }
            IExpr temp = unitConvert(engine, rest);
            if (temp.isPresent()) {
                return temp;
            }
        }
    }
    return inExpr;
}
Also used : IStringX(org.matheclipse.core.interfaces.IStringX) Level(org.apache.logging.log4j.Level) IInteger(org.matheclipse.core.interfaces.IInteger) StringUtils(org.apache.commons.lang3.StringUtils) ThreadLocalNotifyingAppender(org.matheclipse.logging.ThreadLocalNotifyingAppender) TeXUtilities(org.matheclipse.core.eval.TeXUtilities) IDistribution(org.matheclipse.core.interfaces.IDistribution) Trie(org.matheclipse.parser.trie.Trie) VariablesSet(org.matheclipse.core.convert.VariablesSet) Map(java.util.Map) EvalEngine(org.matheclipse.core.eval.EvalEngine) ID(org.matheclipse.core.expression.ID) IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) Set(java.util.Set) LevenshteinDistance(org.apache.commons.text.similarity.LevenshteinDistance) JSBuilder(org.matheclipse.core.form.output.JSBuilder) ISymbol(org.matheclipse.core.interfaces.ISymbol) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) MathMLUtilities(org.matheclipse.core.eval.MathMLUtilities) Logger(org.apache.logging.log4j.Logger) StringFunctions(org.matheclipse.core.builtin.StringFunctions) ExprParser(org.matheclipse.core.parser.ExprParser) GraphExpr(org.matheclipse.core.expression.data.GraphExpr) StandardTokenizer(org.apache.lucene.analysis.standard.StandardTokenizer) TrieBuilder(org.matheclipse.parser.trie.TrieBuilder) IEvaluator(org.matheclipse.core.interfaces.IEvaluator) IFraction(org.matheclipse.core.interfaces.IFraction) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Encode(org.owasp.encoder.Encode) Message(org.apache.logging.log4j.message.Message) WriterOutputStream(org.matheclipse.core.eval.util.WriterOutputStream) Documentation(org.matheclipse.core.form.Documentation) TrieMatch(org.matheclipse.parser.trie.TrieMatch) Suppliers(com.google.common.base.Suppliers) FuzzyParser(org.matheclipse.api.parser.FuzzyParser) ThreadLocalNotifierClosable(org.matheclipse.logging.ThreadLocalNotifyingAppender.ThreadLocalNotifierClosable) SyntaxError(org.matheclipse.parser.client.SyntaxError) Soundex(org.apache.commons.codec.language.Soundex) PrintStream(java.io.PrintStream) CharTermAttribute(org.apache.lucene.analysis.tokenattributes.CharTermAttribute) TokenStream(org.apache.lucene.analysis.TokenStream) F(org.matheclipse.core.expression.F) IAST(org.matheclipse.core.interfaces.IAST) IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol) StringWriter(java.io.StringWriter) PorterStemFilter(org.apache.lucene.analysis.en.PorterStemFilter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Config(org.matheclipse.core.basic.Config) GraphFunctions(org.matheclipse.core.builtin.GraphFunctions) IOException(java.io.IOException) StringEscapeUtils(org.apache.commons.text.StringEscapeUtils) S(org.matheclipse.core.expression.S) StringReader(java.io.StringReader) ElementData1(org.matheclipse.core.data.ElementData1) TeXParser(org.matheclipse.core.form.tex.TeXParser) IExpr(org.matheclipse.core.interfaces.IExpr) Comparator(java.util.Comparator) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) RomanArabicConverter(com.baeldung.algorithms.romannumerals.RomanArabicConverter) FuzzyParser(org.matheclipse.api.parser.FuzzyParser) IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) SyntaxError(org.matheclipse.parser.client.SyntaxError) TeXParser(org.matheclipse.core.form.tex.TeXParser) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST)

Example 2 with TeXParser

use of org.matheclipse.core.form.tex.TeXParser in project symja_android_library by axkr.

the class TeXConverterTestCase method setUp.

/**
 * The JUnit setup method
 */
@Override
protected void setUp() {
    try {
        // F.initSymbols();
        F.await();
        EvalEngine.get().setRelaxedSyntax(true);
        texConverter = new TeXParser(EvalEngine.get());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : TeXParser(org.matheclipse.core.form.tex.TeXParser)

Aggregations

RomanArabicConverter (com.baeldung.algorithms.romannumerals.RomanArabicConverter)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Suppliers (com.google.common.base.Suppliers)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Soundex (org.apache.commons.codec.language.Soundex)1 StringUtils (org.apache.commons.lang3.StringUtils)1 StringEscapeUtils (org.apache.commons.text.StringEscapeUtils)1 LevenshteinDistance (org.apache.commons.text.similarity.LevenshteinDistance)1 Level (org.apache.logging.log4j.Level)1