private static void checkRange( NestedListContainer nlc ){ for( NestedList nl: nlc.getNestedLists() ){ if( nl.getClass() == NestedListContainer.class ) checkRange( (NestedListContainer)nl ); else checkRange( (ContentElement)nl ); } }
/** * Removes all empty Structures from a NestedListContainer and all substructures. */ public static NestedListContainer eliminateEmptyStructures( NestedListContainer nlc ){ for(int i=nlc.size()-1; i>=0; i--){ NestedList nl = nlc.getNestedList(i); if( nl.getClass()==NestedListContainer.class ) eliminateEmptyStructures( (NestedListContainer)nl ); if( nl.empty() )nlc.remove( nl ); } return nlc; }
/** * Generates HTML Output for a {@link NestedList}. */ private static String nestedListToHtml( NestedList nl ){ if( nl == null ) { return "null"; } StringBuilder result = new StringBuilder(); if( nl.getClass()==NestedListElement.class ){ result.append( "<li>\n"+ contentElementToHtml( (NestedListElement)nl ) +"</li>\n" ); } else{ result.append("<table class=\"NestedList\">\n" + "<tr><th class=\"NestedList\">NestedList</th></tr>\n"+ "<tr><td class=\"NestedList\">" ); result.append((((NestedListContainer)nl).isNumbered()?"<ol>":"<ul>")+"\n" ); for( NestedList nl2 : ((NestedListContainer)nl).getNestedLists() ) { result.append( nestedListToHtml( nl2 ) ); } result.append((((NestedListContainer)nl).isNumbered()?"</ol>":"</ul>")+"\n"); result.append("</td></tr>\n" ); result.append("</table>\n"); } return result.toString(); }
NestedListContainer result = new NestedListContainer(numbered); result.setSrcSpan(new SrcSpan(sm.getSrcPos(lineSpans.getFirst() .getStart()), -1)); result.getSrcSpan().setEnd( sm.getSrcPos(nestedListSpans.getLast().getEnd())); if (t == lineType.NESTEDLIST || t == lineType.NESTEDLIST_NR) result.add(buildNestedList(sm, cepp, nestedListSpans, t)); result.add((NestedListElement) parseContentElement(sm, cepp, s, new NestedListElement()));
private static void checkRange( SectionContent s ){ List<SrcSpan> eil = new ArrayList<SrcSpan>(); if( s.getTitleElement()!= null ){ checkRange( s.getTitleElement() ); eil.add( s.getTitleElement().getSrcSpan() ); } for( Paragraph p: s.getParagraphs() ){ checkRange( p ); eil.add( p.getSrcSpan() ); } for( DefinitionList dl: s.getDefinitionLists() ){ checkRange( dl ); eil.add( dl.getSrcSpan() ); } for( NestedListContainer nl: s.getNestedLists() ){ checkRange( nl ); eil.add( nl.getSrcSpan() ); } for( Table t: s.getTables() ){ checkRange( t ); eil.add( t.getSrcSpan() ); } s.setSrcSpan( getEvalInfo( s.getSrcSpan(), eil)); }
/** * Removes all empty Structures from a SectionContent and all substructures. */ public static SectionContent eliminateEmptyStructures( SectionContent sc ){ for( int i=sc.nrOfParagraphs()-1; i>=0; i-- ){ Paragraph p = sc.getParagraph(i); if( p.empty() ) sc.removeParagraph( p ); } for( int i=sc.nrOfDefinitionLists()-1; i>=0; i--){ DefinitionList dl = sc.getDefinitionList(i); eliminateEmptyStructures( dl ); if( dl.empty() ) sc.removeDefinitionList( dl ); } for( int i=sc.nrOfNestedLists()-1; i>=0; i--){ NestedListContainer nl = sc.getNestedList(i); eliminateEmptyStructures( nl ); if( nl.empty() ) sc.removeNestedList( nl ); } for( int i=sc.nrOfTables()-1; i>=0; i--){ Table t = sc.getTable(i); eliminateEmptyStructures( t ); if( t.empty() ) sc.removeTable( t ); } return sc; }
private void setLists(Article article, ParsedPage page) { List<List<String>> lists = new ArrayList<List<String>>(); for (DefinitionList dl : page.getDefinitionLists()) { List<String> l = new ArrayList<String>(); for (ContentElement c : dl.getDefinitions()) { l.add(c.getText()); } lists.add(l); } for (NestedListContainer dl : page.getNestedLists()) { List<String> l = new ArrayList<String>(); for (NestedList nl : dl.getNestedLists()) { l.add(nl.getText()); } lists.add(l); } article.setLists(lists); }
result += "---"; // If it is not a NestedListElement, it is a NestedListContainer for(NestedList nl2 : ((NestedListContainer)nl).getNestedLists()) { result += "\n"+outputNestedList(nl2, depth+1);
private void setLinksInLists(final List<Link> links, final List<Link> externalLinks, ParsedPage page){ int listId = 0; for (NestedListContainer p : page.getNestedLists()){ int item = 0; for (NestedList list : p.getNestedLists()) { for (de.tudarmstadt.ukp.wikipedia.parser.Link link : list.getLinks()) { Link linkAdded = addLink(links, externalLinks, link, Link.Type.LIST); if (linkAdded != null) { linkAdded.setListId(listId); linkAdded.setListItem(item); } } item++; } listId++; } }