トピックモデルを使った文献スクリーニング (2)

データのダウンロード

ダウンロードはこちらから。

Linuxコマンドでmd5チェックと解凍

md5sum -c pubmed18n0928.xml.gz.md5
gunzip pubmed18n0928.xml.gz

C#を使ってアブストラクトを抽出

using System;
using System.Text;
using System.Xml.Linq;
using System.IO;
using System.Diagnostics;
using System.Collections.Generic;
using System.Xml;

namespace pubmed
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("ファイル名を入力してください");
            string s;
            s = Console.ReadLine();

            Stopwatch watch = new Stopwatch();
            watch.Start();


            StreamWriter pmid = new StreamWriter("PMID.txt", false, Encoding.GetEncoding("shift_jis"));


            StreamWriter absts = new StreamWriter("Absts.txt", false, Encoding.GetEncoding("shift_jis"));


            foreach (XElement el in mystream(s))
            {
                if (el.Element("MedlineCitation").Element("Article").Element("Language").Value == "eng")
                {
                    string Absts = "";
                    foreach (XElement x2 in el.Descendants("AbstractText"))
                    {
                        Absts = Absts + x2.Value;
                    }

                    if (Absts != "")
                    {
                        //アブストラクトに改行文字がふくまれることがある
                        //改行を消すときはスペースで置換しないと単語が連なることがある
                        Absts = Absts.Replace("\r", " ").Replace("\n", " ");
                        pmid.WriteLine(el.Element("MedlineCitation").Element("PMID").Value);
                        absts.WriteLine(Absts);
                    }
                }
            }
            pmid.Close();
            absts.Close();

            watch.Stop();

            Console.WriteLine("経過時間の合計 = {0}", watch.Elapsed);
            Console.ReadLine();
        }
        static IEnumerable<XElement> mystream(string file_name)
        {
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.DtdProcessing = DtdProcessing.Parse;

            using (XmlReader reader = XmlReader.Create(file_name, settings))
            {
                while (reader.Read())
                {
                    if (reader.Name == "PubmedArticle")
                    {
                        yield return XElement.ReadFrom(reader) as XElement;
                    }
                }
            }
        }
    }
}

Perlを使って表記ゆれ対策

touch-sp.hatenablog.com

Rのtext2vecパッケージを使う

touch-sp.hatenablog.com

エンコードのことを何も考えていないがこれでエラーがでない。
すべてを「R」のみで行おうとしたが、実行速度の点で上記のような方法に行き着いた。

結果

いろいろ条件をかえてやってみた。
f:id:touch-sp:20180206170822p:plain:w800