コラムニスト:
ここに私が試したものです。https://github.com/curiprogrammer/WikiToLaTeX/tree/master/src
一例として、テキストを以下に示します。
<!-- Hinweis: Der Artikel [[Konkatenation (Formale Sprache)]] verweist auf diese Überschrift-->
Die '''Konkatenation''' zweier Sprachen <math>L_1</math> und <math>L_2</math> ist die Sprache der Wörter, die durch Hintereinanderschreibung ([[Konkatenation (Wort)|Konkatenation]]) je eines beliebigen Wortes <math>u</math> aus <math>L_1</math> und <math>v</math> aus <math>L_2</math> entsteht:
:<math>L_1 \circ L_2 := \{ uv \mid u \in L_1, v \in L_2 \}</math>.
So sind zum Beispiel die Konkatenationen von verschiedenen Sprachen über dem Alphabet <math>\Sigma = \{ a ,\, b \}</math>:
:<math>\{ a \} \circ \{ ab \} = \{ aab \}</math>
:<math>\{ a ,\, bb \} \circ \{ aa ,\, b \} = \{ aaa ,\, ab ,\, bbaa ,\, bbb \}</math>
:<math>\{ abb ,\, bab \} \circ \{ \varepsilon ,\, aab ,\, bb \} = \{ abb ,\, bab ,\, abbaab ,\, babaab ,\, abbbb ,\, babbb \}</math>
Heinrich Scholz traf sich 1944 mit [[Konrad Zuse]], der im Zuge seiner Doktorarbeit an seinem [[Plankalkül]] arbeitete. Im März 1945 sprach ihm Scholz für die Anwendung seines Logikkalküls seine Anerkennung aus.<ref>[[Hartmut Petzold]],''Moderne Rechenkünstler. Die Industrialisierung der Rechentechnik in Deutschland.'' München, C.H. Beck Verlag, 1992.</ref>
私はそのために私のようないくつかの単語を削除する必要があります。.. LaTeXコードに上見られるように、Wikipediaのコードを変換する<!-- SOMETHING SOMETHING -->
か、他の人を交換してください。例:\開始{式} +と\ nおよび\端{式}と次毎に交換してください。目の前にはコロンがない場合でも、それは常に$でなければならず、また$でなければなりません。...それは自分自身でテキスト2に変換する必要があります|そして、[テキスト2] [TEXT]で事があります。
私はこのプロジェクトを開始するにはどのように文字通り見当がつかない。Javaで.replaceAll()関数があります。私が述べたような状況を必要とするので、しかし、それは動作しません。このプロジェクトを作成する方法上の任意のヒントやアイデア?
前もって感謝します!
hiropon :
あなたはこのような状況のために正規表現を使用することができます。
例:この正規表現は、wikiのタグでテキストホールドをキャプチャすることができます。撮影したテキストの後、あなたはでReplaceAllメソッドを使用することができます。
(:<math>)(.*?)(</math>)
ライブコーディング:https://wandbox.org/permlink/RGE6nIwxLtN1F3GY
import java.util.*;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
class Wandbox
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String regex1 = "(<math>)(.*?)(</math>)";
Pattern p1 = Pattern.compile(regex1);
String regex2 = "(:<math>)(.*?)(</math>)";
Pattern p2 = Pattern.compile(regex2);
while (sc.hasNextLine()) {
String line = sc.nextLine();
// remove html comment tag
String replaced = line.replaceAll("<!--.*-->", "");
Matcher m2 = p2.matcher(replaced);
replaced = m2.replaceAll("\\\\\\\\begin\\{equation}\n$2\n\\\\\\\\end\\{equation\\}\n");
Matcher m1 = p1.matcher(replaced);
replaced = m1.replaceAll("\\$$2\\$");
System.out.println(replaced);
}
}
}