导出维基百科文章以获取摘要信息

本文关键字:文章 获取 信息 百科 | 更新日期: 2023-09-27 18:09:57

我正在尝试从维基百科的文章中获得介绍,以将其包含在报告中。例如,对于本文:http://en.wikipedia.org/wiki/MAP3K8

我想要得到:

丝裂原活化蛋白激酶激酶激酶8是一种酶由MAP3K8基因编码。这个基因被鉴定出来通过其在细胞中的致癌转化活性。的编码蛋白是丝氨酸/苏氨酸蛋白激酶家族的成员。该激酶可以激活MAP激酶和JNK激酶途径。该激酶被证明可以激活IkappaB激酶,从而诱导细胞凋亡核生产NF-kappaB。这种激酶也被发现促进T淋巴细胞生成tnf - α和IL-2激活。对大鼠类似基因的研究表明了直接的影响这种激酶参与NF-kappaB1,p105的蛋白水解(NFKB1)。这个基因也可以利用下游的帧内翻译起始密码子,从而产生含有a的同工异构体短的n端。较短的同工异构体已显示转化活性较弱。在小鼠中,这种基因被称为Tpl2它是一种肿瘤抑制基因它的缺失导致癌症的发生和发展。

我得到了这个URL的页面:http://en.wikipedia.org/wiki/Special:Export/MAP3K8

和我转换代码从这篇文章:http://forums.asp.net/t/1066507.aspx/1到c#:

   HttpWebRequest request  =(HttpWebRequest)HttpWebRequest.Create("http://  en.wikipedia.org/wiki/Special:Export/MAP3K8");
   request.Accept = "text/hmtl";
   request.Credentials = System.Net.CredentialCache.DefaultCredentials;
   HttpWebResponse response = (HttpWebResponse) request.GetResponse();
   Stream responseStream = response.GetResponseStream();
   XmlTextReader reader = new XmlTextReader(responseStream);
   String NS = "http://www.mediawiki.org/xml/export-0.8/";
   XPathDocument doc = new XPathDocument(reader);
   reader.Close();
   response.Close();
   XPathNavigator myxpathnav = doc.CreateNavigator();
   XPathNodeIterator nodesText = myxpathnav.SelectDescendants("text", NS, false);
   while (nodesText.MoveNext())
   {
       ViewBag.Message += nodesText.Current.InnerXml;
   }
   ViewBag.Summary = getSummary(ViewBag.Message);
   return View(); 

getSummary方法,根据PBB模板:http://en.wikipedia.org/wiki/Template:PBB_Controls

我只想得到蛋白质的信息,如果这是遵循这个。

   public string getSummary(string page)
    {
        string res = "";
        //The introduction is in 2 parts: 
        //1st between "{{PBB|geneid=1326}}" and <!-- The PBB_Summary (.)* -->
        string intro = "";
        //2nd between "summary_text =" and "=="
        //http://en.wik    ipedia.org/wiki/Special:Export/MAP3K8 is used as example
        string summary = "";
        try
        {
            intro = page.Split(new string[] { "}}" }, StringSplitOptions.None)[1];
            intro = intro.Split(new string[] { "<!--" }, StringSplitOptions.None)[0];
            intro = deleteMediaWikiTag(intro);
        }
        catch(Exception)
        {
            intro = "";
        }
        try
        {
            summary += page.Split(new string[] { "summary_text =" }, StringSplitOptions.None)[1];
            summary = summary.Split(new string[] { "==" }, StringSplitOptions.None)[0];
            summary = deleteMediaWikiTag(summary);
        }
        catch(Exception)
        {
            summary = "";
        }
        res = intro + "'n'n" + summary;
        return res;
    }
   public string deleteMediaWikiTag(string text)
    {
        string res = "";
        // this is working well
        Regex reg = new Regex("{{.*(}})*|{{|}}|'''|<!--.*-->|]]|([[]){2}");
        res = reg.Replace(text,"");
        //I don't understand what is wrong with this regex
        Regex regprime = new Regex("&lt(.)*(>){1}");
        res = regprime.Replace(res, "PRIME");
        return res;
    }

我的问题是在deleteMediaWikiTag(summary)的执行,因为我失去了总结部分的结尾,这是:

在小鼠中,该基因被称为Tpl2,它是一种肿瘤抑制基因,其缺失有助于癌症的发生和进展。

在被正则表达式处理之前,该文本看起来像:

   <ref name="entrez" /> 
   In mice, this gene is known as Tpl2 and it is a tumor suppressor gene whose absence contributes to the development and progression of cancer.
   <ref>{{cite web|last=DeCicco-Skinner|first=Kathleen|title=Loss of tumor progression locus 2 (tpl2) enhances tumorigenesis and inflammation in two-stage skin carcinogenesis|url=http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3460638/}}</ref>

所以根据我的正则表达式,我期待这样的东西:(PRIME用于突出显示匹配,最后,我将删除所有匹配我的正则表达式)

   PRIME In  mice *.....* PRIME

但是我得到:

   PRIME

所以这个"&lt(.)*(>){1}"与整个部分(第一个&lt和最后一个>但我要求的是只匹配一次的模式>

这个正则表达式有什么问题?我错过什么了吗?也许这是一种更好的解析方式?(但是我找到的解析器都没有说服我)

注:我的解析器使用:http://en.wikipedia.org/wiki/NFKB2或http://en.wikipedia.org/wiki/APOA4,但我想做得更可靠。

导出维基百科文章以获取摘要信息

我真的找不到任何问题与现有的。两个正则表达式都工作得很好。我建议在代码中实现之前使用正则表达式在线测试器。试试这个:http://gskinner.com/RegExr/