org.sweble.wikitext.parser.parser.LinkTargetException Java Examples
The following examples show how to use
org.sweble.wikitext.parser.parser.LinkTargetException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TextConverter.java From JuniperBot with GNU General Public License v3.0 | 6 votes |
public void visit(WtInternalLink link) { try { if (link.getTarget().isResolved()) { PageTitle page = PageTitle.make(config, link.getTarget().getAsString()); if (page.getNamespace().equals(config.getNamespace("Category"))) return; } } catch (LinkTargetException e) { // fall down } /*if (!link.hasTitle()) { iterate(link.getTarget()); } else { String title = getContent(link.getTitle()); String target = UriUtils.encode(getContent(link.getTarget()), "UTF-8"); String url = config.getWikiUrl() + "/wiki/" + target; write(CommonUtils.mdLink(title, url)); }*/ iterate(link.hasTitle() ? link.getTitle() : link.getTarget()); }
Example #2
Source File: WikiFurService.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
private EngProcessedPage processedPage(Article article) { try { PageTitle pageTitle = PageTitle.make(config, article.getTitle()); PageId pageId = new PageId(pageTitle, Integer.parseInt(article.getRevisionId())); return engine.postprocess(pageId, article.getText(), null); } catch (LinkTargetException | EngineException e) { throw new RuntimeException(e); } }
Example #3
Source File: PlainTextConverter.java From dkpro-jwpl with Apache License 2.0 | 5 votes |
public void visit(WtInternalLink link) { currentLinkTitleInCell = null; try { PageTitle page = PageTitle.make(config, link.getTarget().getAsString()); if (page.getNamespace().equals(config.getNamespace("Category"))) { return; } } catch (LinkTargetException e) { logger.warn(e.getLocalizedMessage()); } write(link.getPrefix()); WtLinkTitle pageTitle = link.getTitle(); if (pageTitle == null || pageTitle.isEmpty()) { // remember this as it could be needed to process table rows correctly currentLinkTitleInCell = link.getTarget().getAsString(); if(currentLinkTitleInCell.contains("#")) { // only take the first part of the string, no anchors on pages (divided by '#' symbols) currentLinkTitleInCell = currentLinkTitleInCell.split(Pattern.quote("#"), 2)[0]; } // for regular cases: just write the original value here if(currentCell==null) { write(link.getTarget().getAsString()); } } else { iterate(link.getTitle()); } write(link.getPostfix()); }
Example #4
Source File: ParseUtils.java From dkpro-jwpl with Apache License 2.0 | 5 votes |
/** * Returns CompiledPage produced by the SWEBLE parser using the * SimpleWikiConfiguration. * * @return the parsed page * @throws LinkTargetException * @throws EngineException if the wiki page could not be compiled by the parser * @throws JAXBException * @throws FileNotFoundException */ private static EngProcessedPage getCompiledPage(String text, String title, long revision) throws LinkTargetException, EngineException, FileNotFoundException, JAXBException { WikiConfig config = DefaultConfigEnWp.generate(); PageTitle pageTitle = PageTitle.make(config, title); PageId pageId = new PageId(pageTitle, revision); // Compile the retrieved page WtEngineImpl engine = new WtEngineImpl(config); // Compile the retrieved page return engine.postprocess(pageId, text, null); }
Example #5
Source File: SectionExtractor.java From dkpro-jwpl with Apache License 2.0 | 5 votes |
public void visit(WtInternalLink link) { try { PageTitle page = PageTitle.make(config, link.getTarget().getAsString()); if (page.getNamespace().equals(config.getNamespace("Category"))) { return; }else{ String curLinkTitle=""; for(AstNode n:link.getTitle()){ if(n instanceof AstText){ curLinkTitle = ((AstText)n).getContent().trim(); } } if(curLinkTitle.isEmpty()){ bodyBuilder.append(link.getTarget()); }else{ bodyBuilder.append(curLinkTitle); } } } catch (LinkTargetException e) { } }
Example #6
Source File: SwebleParserUtil.java From wikiforia with GNU General Public License v2.0 | 5 votes |
public static EngProcessedPage parsePage(WikiConfig config, String title, long revision, String markup) throws EngineException, LinkTargetException { WtEngineImpl engine = new WtEngineImpl(config); PageTitle pageTitle = PageTitle.make(config, title); PageId pageId = new PageId(pageTitle, revision); return parseWikipage(engine, pageId, markup); }
Example #7
Source File: SwebleTextAstWalker.java From wikiforia with GNU General Public License v2.0 | 5 votes |
public void visit(WtInternalLink link) { try { if (link.getTarget().isResolved()) { PageTitle page = PageTitle.make(config, link.getTarget().getAsString()); if (page.getNamespace().equals(config.getNamespace("Category"))) { return; } else if(page.getNamespace().isFileNs() || page.getNamespace().isMediaNs()) { return; } } } catch (LinkTargetException e) { } //int start = sb.length(); if(!isInsideFilteredSection()) { sb.append(link.getPrefix()); } if (!link.hasTitle()) { iterate(link.getTarget()); } else { iterate(link.getTitle()); } if(!isInsideFilteredSection()) { sb.append(link.getPostfix()); } //int end = sb.length(); }
Example #8
Source File: TextParser.java From wikiforia with GNU General Public License v2.0 | 4 votes |
public void visit(WtInternalLink link) { try { if (link.getTarget().isResolved()) { PageTitle page = PageTitle.make(config, link.getTarget().getAsString()); if (page.getNamespace().equals(config.getNamespace("Category"))) { sb.flush(); parser.category(context, link.getTarget().getAsString(), page.getTitle().replace('_', ' '), sb.length()); return; } else if(page.getNamespace().isFileNs() || page.getNamespace().isMediaNs()) { return; } } } catch (LinkTargetException e) { } sb.flush(); int start = sb.length(); if(!isInsideFilteredSection()) { sb.append(link.getPrefix()); } if (!link.hasTitle()) iterate(link.getTarget()); else iterate(link.getTitle()); if(!isInsideFilteredSection()) { sb.append(link.getPostfix()); } sb.flush(); int end = sb.length(); start = trimStart(start); end = trimEnd(end); if(start < end) { String target = link.getTarget().getAsString(); if(target.startsWith("#")) { parser.anchor(context, page.getTitle(), target.substring(1), true, start, end); } else { int hashIndex = target.lastIndexOf('#'); if(hashIndex == -1) { parser.anchor(context, link.getTarget().getAsString(), null, true, start, end); } else { parser.anchor(context, target.substring(0,hashIndex), target.substring(hashIndex+1), true, start, end); } } } }
Example #9
Source File: ParseUtils.java From dkpro-jwpl with Apache License 2.0 | 2 votes |
/** * Extracts sections (without title) from Wikitext. * * @param text article text with wiki markup * @param title article title * @param revision the revision id * @return list of ExtractedSections */ public static List<ExtractedSection> getSections(String text, String title, long revision) throws LinkTargetException, EngineException, FileNotFoundException, JAXBException{ return (List<ExtractedSection>) parsePage(new SectionExtractor(), text, title, revision); }
Example #10
Source File: ParseUtils.java From dkpro-jwpl with Apache License 2.0 | 2 votes |
/** * Extracts sections (without title) from Wikitext. * * @param text article text with wiki markup * @param title article title * @param revision the revision id * @param templatesToMark a list of template names that should be annotated in the text * @return list of ExtractedSections * @throws EngineException if the wiki page could not be compiled by the parser */ public static List<ExtractedSection> getSections(String text, String title, long revision, List<String> templatesToMark) throws LinkTargetException, EngineException, FileNotFoundException, JAXBException{ return (List<ExtractedSection>) parsePage(new SectionExtractor(templatesToMark), text, title, revision); }
Example #11
Source File: ParseUtils.java From dkpro-jwpl with Apache License 2.0 | 2 votes |
/** * Extracts template names from Wikitext by descending into every node and looking for templates. * Results may contain duplicates if template appears multiple times in the article. * * @param text article text with wiki markup * @param title article title * @return list of template names * @throws EngineException if the wiki page could not be compiled by the parser */ public static List<String> getTemplateNames(String text, String title) throws LinkTargetException, EngineException, FileNotFoundException, JAXBException{ return (List<String>) parsePage(new TemplateNameExtractor(), text, title, -1); }
Example #12
Source File: ParseUtils.java From dkpro-jwpl with Apache License 2.0 | 2 votes |
/** * Parses the page with the Sweble parser using a SimpleWikiConfiguration * and the provided visitor. * * @return the parsed page. The actual return type depends on the provided * visitor. You have to cast the return type according to the return * type of the go() method of your visitor. * @throws EngineException if the wiki page could not be compiled by the parser */ private static Object parsePage(AstVisitor v, String text, String title, long revision) throws LinkTargetException, EngineException, FileNotFoundException, JAXBException{ // Use the provided visitor to parse the page return v.go(getCompiledPage(text, title, revision).getPage()); }
Example #13
Source File: TemplateArgument.java From wikiforia with GNU General Public License v2.0 | 2 votes |
/** * Parse custom * @param model the model for the context * @param parser the parser to use * @param <T> model type * @throws EngineException * @throws LinkTargetException * @remarks It throws exceptions because the arguments needs to be recursively parsed which * means that the engine is invoked again, and this can fail. Total failure is undesirable; * this design allows the user to handle the error. */ public abstract <T,Out> void parse(T model, AnnotationParser<T,Out> parser) throws EngineException, LinkTargetException;
Example #14
Source File: TemplateArgument.java From wikiforia with GNU General Public License v2.0 | 2 votes |
/** * Parse as text, append result to current parser. * @throws EngineException * @throws LinkTargetException * @remarks It throws exceptions because the arguments needs to be recursively parsed which * means that the engine is invoked again, and this can fail. Total failure is undesirable; * this design allows the user to handle the error. */ public abstract void parse() throws EngineException, LinkTargetException;