2010-10-20 76 views
0

当我搜索关键字“数据”,我得到abtract纸在数字图书馆:如何删除字符串中的html标记?

Many organizations often underutilize their existing <span class='snippet'>data</span> warehouses. In this paper, we suggest a way of acquiring more information from corporate <span class='snippet'>data</span> warehouses without the complications and drawbacks of deploying additional software systems. Association-rule mining, which captures co-occurrence patterns within <span class='snippet'>data</span>, has attracted considerable efforts from <span class='snippet'>data</span> warehousing researchers and practitioners alike. Unfortunately, most <span class='snippet'>data</span> mining tools are loosely coupled, at best, with the <span class='snippet'>data</span> warehouse repository. Furthermore, these tools can often find association rules only within the main fact table of the <span class='snippet'>data</span> warehouse (thus ignoring the information-rich dimensions of the star schema) and are not easily applied on non-transaction level <span class='snippet'>data</span> often found in <span class='snippet'>data</span> warehouses 

我怎样才能去除所有标签<span class='snippet'>..</span>,但仍保持keywod数据有abtract这样:

许多组织经常利用现有的数据仓库。在本文中,我们建议从企业数据仓库获取更多信息的方法,而不会出现部署其他软件系统的复杂性和缺陷。关联规则挖掘捕获数据中的同现模式,吸引了数据仓库研究人员和从业人员的大量努力。不幸的是,大多数数据挖掘工具充其量与数据仓库存在松散耦合。此外,这些工具通常只能在数据仓库的主事实表中找到关联规则(因此忽略了星型模式的信息丰富的维度),并且不容易应用于通常在数据仓库中发现的非事务级数据

+0

它总是会是'?您可以使用简单的字符串替换或正则表达式。 – Marko 2010-10-20 03:45:17

+0

如果有任何一种HTML可以存在,我建议你使用解析器而不是正则表达式。看看这个wiki如果你想要一个好的解析器... http://stackoverflow.com/questions/773340/can-you-provide-an-example-of-parsing-html-with-your-favorite-parser – InSane 2010-10-20 03:50:53

+0

re :正则表达式和HTML ...塔尔是龙。 – 2010-10-20 03:53:48

回答

2

strip_tags()是你的朋友。 Code kindly copied from here

public static String strip_tags(String text, String allowedTags) { 
     String[] tag_list = allowedTags.split(","); 
     Arrays.sort(tag_list); 

     final Pattern p = Pattern.compile("<[/!]?([^\\\\s>]*)\\\\s*[^>]*>", 
       Pattern.CASE_INSENSITIVE); 
     Matcher m = p.matcher(text); 

     StringBuffer out = new StringBuffer(); 
     int lastPos = 0; 
     while (m.find()) { 
      String tag = m.group(1); 
      // if tag not allowed: skip it 
      if (Arrays.binarySearch(tag_list, tag) < 0) { 
       out.append(text.substring(lastPos, m.start())).append(" "); 

      } else { 
       out.append(text.substring(lastPos, m.end())); 
      } 
      lastPos = m.end(); 
     } 
     if (lastPos > 0) { 
      out.append(text.substring(lastPos)); 
      return out.toString().trim(); 
     } else { 
      return text; 
     } 
    } 
相关问题