Add support for links (unreconciled for now)
This commit is contained in:
parent
deeed2204b
commit
b8a781d366
@ -16,19 +16,16 @@ import com.google.common.io.CharStreams;
|
|||||||
import de.fau.cs.osr.ptk.common.AstVisitor;
|
import de.fau.cs.osr.ptk.common.AstVisitor;
|
||||||
import de.fau.cs.osr.ptk.common.ParserCommon;
|
import de.fau.cs.osr.ptk.common.ParserCommon;
|
||||||
|
|
||||||
/*
|
|
||||||
import org.sweble.wikitext.engine.PageId;
|
|
||||||
import org.sweble.wikitext.engine.PageTitle;
|
|
||||||
import org.sweble.wikitext.engine.WtEngineImpl;
|
|
||||||
import org.sweble.wikitext.engine.EngineException;
|
|
||||||
import org.sweble.wikitext.engine.config.WikiConfig;
|
|
||||||
import org.sweble.wikitext.engine.nodes.EngProcessedPage;
|
|
||||||
import org.sweble.wikitext.engine.utils.DefaultConfigEnWp; */
|
|
||||||
import org.sweble.wikitext.parser.ParserConfig;
|
import org.sweble.wikitext.parser.ParserConfig;
|
||||||
import org.sweble.wikitext.parser.utils.SimpleParserConfig;
|
import org.sweble.wikitext.parser.utils.SimpleParserConfig;
|
||||||
import org.sweble.wikitext.parser.WikitextParser;
|
import org.sweble.wikitext.parser.WikitextParser;
|
||||||
import org.sweble.wikitext.parser.nodes.WtNode;
|
import org.sweble.wikitext.parser.nodes.WtNode;
|
||||||
import org.sweble.wikitext.parser.nodes.WtText;
|
import org.sweble.wikitext.parser.nodes.WtText;
|
||||||
|
import org.sweble.wikitext.parser.nodes.WtInternalLink;
|
||||||
|
import org.sweble.wikitext.parser.nodes.WtExternalLink;
|
||||||
|
import org.sweble.wikitext.parser.nodes.WtLinkTitle;
|
||||||
|
import org.sweble.wikitext.parser.nodes.WtLinkTitle.WtNoLinkTitle;
|
||||||
|
import org.sweble.wikitext.parser.nodes.WtUrl;
|
||||||
import org.sweble.wikitext.parser.nodes.WtTable;
|
import org.sweble.wikitext.parser.nodes.WtTable;
|
||||||
import org.sweble.wikitext.parser.nodes.WtTableHeader;
|
import org.sweble.wikitext.parser.nodes.WtTableHeader;
|
||||||
import org.sweble.wikitext.parser.nodes.WtTableRow;
|
import org.sweble.wikitext.parser.nodes.WtTableRow;
|
||||||
@ -77,13 +74,15 @@ public class WikitextImporter extends TabularImportingParserBase {
|
|||||||
public List<List<String>> rows;
|
public List<List<String>> rows;
|
||||||
private List<String> currentRow;
|
private List<String> currentRow;
|
||||||
private StringBuilder currentCellString;
|
private StringBuilder currentCellString;
|
||||||
// private String currentCellLink;
|
private String currentInternalLink;
|
||||||
|
private String currentExternalLink;
|
||||||
|
|
||||||
public WikitextTableVisitor() {
|
public WikitextTableVisitor() {
|
||||||
header = null;
|
header = null;
|
||||||
rows = new ArrayList<List<String>>();
|
rows = new ArrayList<List<String>>();
|
||||||
currentCellString = null;
|
currentCellString = null;
|
||||||
// currentCellLink = null;
|
currentInternalLink = null;
|
||||||
|
currentExternalLink = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -145,6 +144,31 @@ public class WikitextImporter extends TabularImportingParserBase {
|
|||||||
currentCellString.append(text.getContent());
|
currentCellString.append(text.getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void visit(WtNoLinkTitle e) {
|
||||||
|
if (currentInternalLink != null) {
|
||||||
|
currentCellString.append(currentInternalLink);
|
||||||
|
} else if (currentExternalLink != null) {
|
||||||
|
currentCellString.append(currentExternalLink);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void visit(WtLinkTitle e) {
|
||||||
|
iterate(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void visit(WtInternalLink e) {
|
||||||
|
currentInternalLink = e.getTarget().getAsString();
|
||||||
|
iterate(e);
|
||||||
|
currentInternalLink = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void visit(WtExternalLink e) {
|
||||||
|
WtUrl url = e.getTarget();
|
||||||
|
currentExternalLink = url.getProtocol() + ":" + url.getPath();
|
||||||
|
iterate(e);
|
||||||
|
currentExternalLink = null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object after(WtNode node, Object result)
|
protected Object after(WtNode node, Object result)
|
||||||
{
|
{
|
||||||
|
@ -100,6 +100,66 @@ public class WikitextImporterTests extends ImporterTest {
|
|||||||
Assert.assertEquals(project.rows.get(1).cells.get(2).value, "f");
|
Assert.assertEquals(project.rows.get(1).cells.get(2).value, "f");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void readTableWithLinks() {
|
||||||
|
// Data credits: Wikipedia contributors, https://de.wikipedia.org/w/index.php?title=Agenturen_der_Europäischen_Union&action=edit
|
||||||
|
String input = "\n"
|
||||||
|
+"{|\n"
|
||||||
|
+"|-\n"
|
||||||
|
+"| [[Europäisches Zentrum für die Förderung der Berufsbildung|Cedefop]] || Cedefop || [http://www.cedefop.europa.eu/]\n"
|
||||||
|
+"|-\n"
|
||||||
|
+"| [[Europäische Stiftung zur Verbesserung der Lebens- und Arbeitsbedingungen]] || EUROFOUND || [http://www.eurofound.europa.eu/]\n"
|
||||||
|
+"|-\n"
|
||||||
|
+"| [[Europäische Beobachtungsstelle für Drogen und Drogensucht]] || EMCDDA || [http://www.emcdda.europa.eu/]\n"
|
||||||
|
+"|-\n"
|
||||||
|
+"|}\n";
|
||||||
|
|
||||||
|
try {
|
||||||
|
prepareOptions(0, 0, 0, 0, true);
|
||||||
|
parse(input);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Assert.fail("Parsing failed", e);
|
||||||
|
}
|
||||||
|
Assert.assertEquals(project.columnModel.columns.size(), 3);
|
||||||
|
Assert.assertEquals(project.rows.size(), 3);
|
||||||
|
Assert.assertEquals(project.rows.get(0).cells.size(), 3);
|
||||||
|
Assert.assertEquals(project.rows.get(0).cells.get(0).value, "Cedefop");
|
||||||
|
Assert.assertEquals(project.rows.get(1).cells.get(2).value, "http://www.eurofound.europa.eu/");
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
@Test
|
||||||
|
public void readStyledTableWithHeader() {
|
||||||
|
// Data credits: Wikipedia contributors, https://de.wikipedia.org/w/index.php?title=Agenturen_der_Europäischen_Union&action=edit
|
||||||
|
String input = "\n"
|
||||||
|
+"{| class=\"wikitable sortable\"\n"
|
||||||
|
+"! style=\"text-align:left; width: 60em\" | Offizieller Name\n"
|
||||||
|
+"! style=\"text-align:left; width: 9em\" | Abkürzung\n"
|
||||||
|
+"! style=\"text-align:left; width: 6em\" | Website\n"
|
||||||
|
+"! style=\"text-align:left; width: 15em\" | Standort\n"
|
||||||
|
+"! style=\"text-align:left; width: 18em\" | Staat\n"
|
||||||
|
+"! style=\"text-align:left; width: 6em\" | Gründung\n"
|
||||||
|
+"! style=\"text-align:left; width: 50em\" | Anmerkungen\n"
|
||||||
|
+"|-\n"
|
||||||
|
+"| [[Europäisches Zentrum für die Förderung der Berufsbildung]] || Cedefop || [http://www.cedefop.europa.eu/] || [[Thessaloniki]] || {{Griechenland}} || 1975 ||\n"
|
||||||
|
+"|-\n"
|
||||||
|
+"| [[Europäische Stiftung zur Verbesserung der Lebens- und Arbeitsbedingungen]] || EUROFOUND || [http://www.eurofound.europa.eu/] || [[Dublin]] || {{Irland}} || 1975 ||\n"
|
||||||
|
+"|-\n"
|
||||||
|
+"| [[Europäische Beobachtungsstelle für Drogen und Drogensucht]] || EMCDDA || [http://www.emcdda.europa.eu/] || [[Lissabon]] || {{Portugal}} || 1993 ||\n"
|
||||||
|
+"|-\n"
|
||||||
|
+"|}\n";
|
||||||
|
|
||||||
|
try {
|
||||||
|
prepareOptions(0, 0, 0, 0, true);
|
||||||
|
parse(input);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Assert.fail("Parsing failed", e);
|
||||||
|
}
|
||||||
|
Assert.assertEquals(project.columnModel.columns.size(), 7);
|
||||||
|
Assert.assertEquals(project.rows.size(), 3);
|
||||||
|
Assert.assertEquals(project.rows.get(0).cells.size(), 7);
|
||||||
|
Assert.assertEquals(project.rows.get(0).cells.get(0).value, "Europäisches Zentrum für die Förderung der Berufsbildung");
|
||||||
|
Assert.assertEquals(project.rows.get(1).cells.get(2).value, "http://www.eurofound.europa.eu/");
|
||||||
|
}*/
|
||||||
|
|
||||||
//--helpers--
|
//--helpers--
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user