我正试图从维基百科的文章中得到介绍,以便将其纳入报告。例如,对于本文:http://en.wikipedia.org/wiki/MAP3K8
我想要:
丝裂原活化蛋白激酶8是一种由MAP3K8基因编码的酶.该基因是通过其在细胞中的致癌转化活性来鉴定的。编码蛋白是丝氨酸/苏氨酸蛋白激酶家族的成员。 该激酶可激活MAP激酶和JNK激酶通路。该激酶能激活IkappaB激酶,从而诱导NF-kappaB的核产生.该激酶还能促进T淋巴细胞活化过程中TNF-α和IL-2的产生.对大鼠类似基因的研究表明,该激酶直接参与NF-kappaB1 1,p105 (NFKB1)的蛋白水解。该基因还可能利用下游的帧内翻译起始密码子,从而产生一个含有较短N端的异构体。较短的异构体表现出较弱的转化活性。在小鼠中,该基因被称为Tpl2,它是一种肿瘤抑制基因,其缺失参与了癌症的发生和发展。
我得到了这个网址: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模板: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("<(.)*(>){1}");
res = regprime.Replace(res, "PRIME");
return res;
}我的问题是在执行deleteMediaWikiTag(summary)时,因为我失去了摘要部分的结尾,即:
在小鼠中,该基因被称为Tpl2,它是一种肿瘤抑制基因,其缺失参与了癌症的发生和发展。
在由regex处理之前,以下文本如下所示:
<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>因此,根据我的regex,我期待这样的东西:(PRIME用于突出显示匹配,最后,我将删除与regex匹配的所有内容)
PRIME In mice *.....* PRIME但我明白:
PRIME所以这个"<(.)*(>){1}"与整个部分(第一个<和最后一个>)是匹配的,但是我要求匹配一个只有一次的模式>,如果我把所有的东西都取下来的话,这是不止一次的。
这个Regex怎么了?我错过了什么吗?也许这是一种更好的解析方法吗?(但我发现的解析者中没有一个让我信服)
我的解析器可以使用:http://en.wikipedia.org/wiki/NFKB2或http://en.wikipedia.org/wiki/APOA4,但我希望更可靠地完成它。
发布于 2013-04-21 11:28:11
我真的找不到退出的那个有任何问题。这两个正则表达式都正常工作。我建议在代码中实现之前使用正则表达式在线测试器。试试这个:http://gskinner.com/RegExr/
https://stackoverflow.com/questions/16085526
复制相似问题