當前位置: 首頁>>代碼示例>>Java>>正文


Java MathTokenizer類代碼示例

本文整理匯總了Java中cz.muni.fi.mias.math.MathTokenizer的典型用法代碼示例。如果您正苦於以下問題:Java MathTokenizer類的具體用法?Java MathTokenizer怎麽用?Java MathTokenizer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MathTokenizer類屬於cz.muni.fi.mias.math包,在下文中一共展示了MathTokenizer類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: process

import cz.muni.fi.mias.math.MathTokenizer; //導入依賴的package包/類
private MIaSTermContainer process(String query) throws IOException {
    System.out.println(query);
    List<MIaSTerm> result = new ArrayList<>();
    String mathQuery = "<html>" + query + "</html>";
    MathTokenizer mt = new MathTokenizer(new StringReader(mathQuery), true, MathTokenizer.MathMLType.BOTH);
    mt.reset();
    Map<Integer, List<Formula>> forms = mt.getFormulae();
    for (int i = 0; i < forms.size(); i++) {
        List<Formula> flist = forms.get(i);
        for (Formula f : flist) {
            result.add(new MIaSTerm(Formula.nodeToString(f.getNode(), false, MathMLConf.getElementDictionary(), MathMLConf.getAttrDictionary(), MathMLConf.getIgnoreNode()), f.getWeight()));
        }
    }
    MIaSTermContainer fc = new MIaSTermContainer();
    fc.setForms(result);
    return fc;
}
 
開發者ID:martinliska,項目名稱:WebMIaS,代碼行數:18,代碼來源:MtermResource.java

示例2: processRequest

import cz.muni.fi.mias.math.MathTokenizer; //導入依賴的package包/類
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("application/json;charset=UTF-8");

    String query = request.getParameter("mathml");

    List<MIaSTerm> result = new ArrayList<>();
    String mathQuery = "<html>" + query + "</html>";
    MathTokenizer mt = new MathTokenizer(new StringReader(mathQuery), true, MathTokenizer.MathMLType.BOTH);
    Map<Integer, List<Formula>> forms = mt.getFormulae();
    for (int i = 0; i < forms.size(); i++) {
        List<Formula> flist = forms.get(i);
        for (Formula f : flist) {
            result.add(new MIaSTerm(Formula.nodeToString(f.getNode(), false, MathMLConf.getElementDictionary(), MathMLConf.getAttrDictionary(), MathMLConf.getIgnoreNode()), f.getWeight()));
        }
    }
    MIaSTermContainer fc = new MIaSTermContainer();
    fc.setForms(result);

    StringWriter sw = new StringWriter();
    JsonMarshallHelper.marshall(fc, sw);

    response.getWriter().write(sw.toString());
}
 
開發者ID:martinliska,項目名稱:WebMIaS,代碼行數:25,代碼來源:MtermServlet.java

示例3: getType

import cz.muni.fi.mias.math.MathTokenizer; //導入依賴的package包/類
private MathTokenizer.MathMLType getType(String variant) {
    if (variant == null) {
        return MathTokenizer.MathMLType.BOTH;
    }
    if (variant.equals("pmath")) {
        return MathTokenizer.MathMLType.PRESENTATION;
    }
    if (variant.equals("cmath")) {
        return MathTokenizer.MathMLType.CONTENT;
    }
    return MathTokenizer.MathMLType.BOTH;
}
 
開發者ID:martinliska,項目名稱:WebMIaS,代碼行數:13,代碼來源:ProcessServlet.java

示例4: printTimes

import cz.muni.fi.mias.math.MathTokenizer; //導入依賴的package包/類
private void printTimes() {
    LOG.info("---------------------------------");
    LOG.info(Settings.EMPTY_STRING);
    LOG.info("{} DONE in total time {} ms",progress,System.currentTimeMillis() - startTime);
    LOG.info("CPU time {} ms",getCpuTime());
    LOG.info("user time {} ms",getUserTime());
    MathTokenizer.printFormulaeCount(); // TODO
    LOG.info(Settings.EMPTY_STRING);
}
 
開發者ID:martinliska,項目名稱:MIaS,代碼行數:10,代碼來源:Indexing.java

示例5: getDocuments

import cz.muni.fi.mias.math.MathTokenizer; //導入依賴的package包/類
@Override
public List<Document> getDocuments() throws IOException {
    Document document = source.createDocument();
    
    HtmlDocumentExtractor htmldoc = new HtmlDocumentExtractor(source.resetStream());

    String arxivId = htmldoc.getArxivId();
    if (arxivId != null) {
        document.removeField("id");
        Field arxivIdField = new StringField("id", arxivId, Field.Store.YES);
        document.add(arxivIdField);
    }

    String title = htmldoc.getTitle();
    if (title != null) {
        document.removeField("title");
        Field titleField = new TextField("title", title, Field.Store.YES);
        titleField.setBoost(Float.parseFloat("10.0"));
        document.add(titleField);
    }

    String authors = htmldoc.getAuthors();
    if (authors != null) {
        Field authorsField = new StringField("authors", authors, Field.Store.YES);
        authorsField.setBoost(Float.parseFloat("10.0"));
        document.add(authorsField);
    }
    
    String content = htmldoc.getBody();
    if (content != null) {
        document.add(new TextField("content", content, Field.Store.NO));
    }

    InputStreamReader isr = new InputStreamReader(source.resetStream(), "UTF-8");
    document.add(new TextField("pmath", new MathTokenizer(isr, true, MathTokenizer.MathMLType.PRESENTATION)));
    isr = new InputStreamReader(source.resetStream(), "UTF-8");
    document.add(new TextField("cmath", new MathTokenizer(isr, true, MathTokenizer.MathMLType.CONTENT)));
    
    return Arrays.asList(document);
}
 
開發者ID:martinliska,項目名稱:MIaS,代碼行數:41,代碼來源:HtmlDocument.java

示例6: addMathQueries

import cz.muni.fi.mias.math.MathTokenizer; //導入依賴的package包/類
private Map<String, Float> addMathQueries(String mathQuery, BooleanQuery bq, MathTokenizer.MathMLType variant, boolean extractSubformulae, boolean reduceWeighting) {
    MathTokenizer mt = new MathTokenizer(new StringReader(mathQuery), extractSubformulae, variant, reduceWeighting);
    try {
        mt.reset();
    } catch (IOException ex) {
        LOG.fatal(ex);
    }
    Map<String, Float> queryForms = mt.getQueryFormulae();
    List<Query> cQueries = getMathQueries(queryForms, variant);
    for (Query q : cQueries) {
        bq.add(q, BooleanClause.Occur.SHOULD);
    }
    return mt.getQueryXMLFormulae();
}
 
開發者ID:martinliska,項目名稱:MIaS,代碼行數:15,代碼來源:Searching.java

示例7: getMathQueries

import cz.muni.fi.mias.math.MathTokenizer; //導入依賴的package包/類
private List<Query> getMathQueries(Map<String, Float> queryForms, MathTokenizer.MathMLType type) {
    String field = (type == MathTokenizer.MathMLType.PRESENTATION ? "p" : "c") + "math";
    List<Query> result = new ArrayList<>();
    Iterator<Map.Entry<String, Float>> it = queryForms.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, Float> entry = it.next();
        Float boost = entry.getValue();
        PayloadTermQuery ptq = new PayloadTermQuery(new Term(field, entry.getKey()), new AveragePayloadFunction());

        ptq.setBoost(boost);
        result.add(ptq);
    }
    return result;
}
 
開發者ID:martinliska,項目名稱:MIaS,代碼行數:15,代碼來源:Searching.java

示例8: create

import cz.muni.fi.mias.math.MathTokenizer; //導入依賴的package包/類
@Override
public Tokenizer create(AttributeFactory af, Reader reader) {
    return new MathTokenizer(reader, subformulae, MathTokenizer.MathMLType.BOTH);
}
 
開發者ID:martinliska,項目名稱:MIaSMath,代碼行數:5,代碼來源:MathTokenizerFactory.java

示例9: getDocuments

import cz.muni.fi.mias.math.MathTokenizer; //導入依賴的package包/類
@Override
public List<Document> getDocuments() throws IOException {
    List<Document> result = new ArrayList<>();
    try {
        DocumentBuilder builder = MIaSUtils.prepareDocumentBuilder();
        org.w3c.dom.Document document = builder.parse(source.resetStream());
        NodeList list = document.getElementsByTagNameNS("*", "math");
        for (int i = 0; i < list.getLength(); i++) {
            Node item = list.item(i);
            String id;
            Node namedItem = item.getAttributes().getNamedItem("id");
            if (namedItem != null) {
                id = namedItem.getNodeValue();
            } else {
                id = String.valueOf(i);
            }
            Document doc = source.createDocument();
            id = doc.get("id") + "#" + id;
            doc.removeField("id");
            doc.add(new StringField("id", id, Field.Store.YES));
            doc.removeField("title");
            doc.add(new TextField("title", id, Field.Store.YES));
            
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            Source xmlSource = new DOMSource(item);
            Result outputTarget = new StreamResult(outputStream);
            TransformerFactory.newInstance().newTransformer().transform(xmlSource, outputTarget);
            InputStream is = new ByteArrayInputStream(outputStream.toByteArray());
            InputStreamReader isr = new InputStreamReader(is, "UTF-8");
            MathTokenizer mathTokenizer = new MathTokenizer(isr, true, MathTokenizer.MathMLType.PRESENTATION);
            mathTokenizer.setFormulaPosition(i+1);
            doc.add(new TextField("pmath", mathTokenizer));
            is.reset();
            isr = new InputStreamReader(is, "UTF-8");
            MathTokenizer mathTokenizer1 = new MathTokenizer(isr, true, MathTokenizer.MathMLType.CONTENT);
            mathTokenizer1.setFormulaPosition(i+1);
            doc.add(new TextField("cmath", mathTokenizer1));
            result.add(doc);
        }
    } catch (TransformerException | SAXException | ParserConfigurationException ex) {
        LOG.fatal(ex);
    }
    return result;
}
 
開發者ID:martinliska,項目名稱:MIaS,代碼行數:45,代碼來源:FormulaDocument.java

示例10: search

import cz.muni.fi.mias.math.MathTokenizer; //導入依賴的package包/類
public SearchResult search(String query, boolean print, int offset, int limit, boolean debug, MathTokenizer.MathMLType variant) {
    return search(query, print, offset, limit, debug, variant, false);
}
 
開發者ID:martinliska,項目名稱:MIaS,代碼行數:4,代碼來源:Searching.java


注:本文中的cz.muni.fi.mias.math.MathTokenizer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。