Beispiel #1
0
        private void _Init()
        {
            if (tagger != null)
            {
                tagger.Dispose();
                tagger = null;
            }

            try
            {
                if (Args != null)
                {
                    tagger = new MeCab.Tagger(Args);
                }
                else
                {
                    tagger = new MeCab.Tagger();
                }

                if (tagger == null)
                {
                    ReportManage.ErrReport(this, "Mecabの起動に失敗しました。インストールされているか確かめてください。");
                    throw new Exception("Mecabの起動に失敗しました。インストールされているか確かめてください。");
                }
            }
            catch
            {
                ReportManage.ErrReport(this, "Mecabの起動に失敗しました。インストールされているか確かめてください。");
                throw new Exception("Mecabの起動に失敗しました。インストールされているか確かめてください。");
            }
        }
Beispiel #2
0
        /// <summary>
        /// このクラスでの実行すること。
        /// </summary>
        /// <param name="runChildren"></param>
        public override void Run(bool runChildren)
        {
            var xaml = GetText();

            try
            {
                var td = TweetData.Parse(xaml);
                this.SetText(td.GetTweetDataElement(DataElement));
                base.Run(runChildren);

                //var obj = System.Xaml.XamlServices.Parse(xaml);
                //if (obj is TweetData)
                //{
                //    var td = obj as TweetData;
                //    this.SetText(td.GetTweetDataElement(DataElement));
                //    base.Run(runChildren);
                //}
                //else
                //{
                //    ReportManage.ErrReport(this, "TweetDataの解釈に失敗しました。");
                //}
            }
            catch
            {
                ReportManage.ErrReport(this, "TweetDataの解釈に失敗しました。");
            }
        }
Beispiel #3
0
 /// <summary>
 ///  ElementAt を適応する。
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="list"></param>
 /// <returns></returns>
 IEnumerable <T> DoElementAt <T>(IEnumerable <T> list)
 {
     if (list.Count() == 0)
     {
         return(list);
     }
     if (ElementAt.HasValue)
     {
         try
         {
             var l = list.ToArray();
             if (ElementAt.Value > -1)
             {
                 return(new T[] { l[ElementAt.Value] });
                 //return new List<T>() { list.ElementAt(ElementAt.Value) };
             }
             else
             {
                 return(new T[] { l[list.Count() + ElementAt.Value] });
                 //   return new List<T>() { list.ElementAt(list.Count() + ElementAt.Value) };
             }
         }
         catch
         {
             ReportManage.ErrReport(this, "ElementAtの値がレンジから外れました。ElementAt:" + ElementAt.Value);
         }
     }
     return(list);
 }
Beispiel #4
0
        public override void Run(bool runChildren)
        {
            currentFileName = FileName.Convert(this);
            baseFileName    = currentFileName;
            if (currentFileName.Length == 0)
            {
                ReportManage.ErrReport(this, "FileNameがありません");
                return;
            }

            var f     = CheckFileSizeAndCreate(System.IO.File.AppendText(currentFileName));
            int count = 0;
            ActionBlock <string> actionBlock = new ActionBlock <string>((n) => {
                if (count % 10000 == 0)
                {
                    f = CheckFileSizeAndCreate(f);
                }
                f.WriteLine(n);
                ReportManage.Report(this, "NextDataRow");
                count++;
            });

            inputBlock = new BufferBlock <string>();
            inputBlock.LinkTo(actionBlock, new DataflowLinkOptions()
            {
                PropagateCompletion = true
            });
            base.Run(runChildren);
            inputBlock.Complete();
            actionBlock.Completion.Wait();
            f.Close();
        }
Beispiel #5
0
        public RawlerBase GetRawlerBase(string xaml)
        {
            object obj = null;

            try
            {
                obj = System.Xaml.XamlServices.Parse(textEditor.Text);
            }
            catch (Exception ex)
            {
                ReportManage.ErrReport(new RawlerBase(), "XAMLの形式がおかしいです" + ex.Message);
            }
            if (obj == null)
            {
                return(null);
            }
            if ((obj is Rawler.Tool.RawlerBase) == false)
            {
                ReportManage.ErrReport(new RawlerBase(), "キャストできませんでした。XAMLの形式がおかしいです");
                return(null);
            }
            else
            {
                return(obj as Rawler.Tool.RawlerBase);
            }
        }
Beispiel #6
0
        /// <summary>
        /// このクラスでの実行すること。
        /// </summary>
        /// <param name="runChildren"></param>
        public override void Run(bool runChildren)
        {
            SetText(GetText());
            var login = this.GetAncestorRawler().OfType <TwitterLogin>().First();

            if (login != null)
            {
                var r = login.Token.Statuses.Update(status => GetText());
                if (r != null)
                {
                    // Tweet posted successfully!
                }
                else
                {
                    ReportManage.ErrReport(this, "ツイートに失敗しました。");
                    // Something bad happened
                }
            }
            else
            {
                ReportManage.ErrReport(this, "上流にTwitterLoginがありません。");
            }



            base.Run(runChildren);
        }
Beispiel #7
0
        public string _Analyze(string txt)
        {
            string r = string.Empty;

            try
            {
                while (tagger == null)
                {
                    _Init();
                    if (tagger == null)
                    {
                        System.Threading.Thread.Sleep(100);
                    }
                }
                r = tagger.parse(txt);
            }
            catch (Exception e)
            {
                ReportManage.ErrReport(this, "形態素解析に失敗しました:" + txt);
            }
            finally
            {
                tagger.Dispose();
                tagger = null;
            }
            return(r);
        }
Beispiel #8
0
        public string Analyze(string txt)
        {
            string r = null;

            try
            {
                while (r == null)
                {
                    if (mecabDotNet == null)
                    {
                        Init();
                    }
                    r = mecabDotNet.mecab_sparse_tostr(txt);
                    if (r == null)
                    {
                        System.Threading.Thread.Sleep(100);
                        Init();
                    }
                }
            }
            catch (Exception e)
            {
                ReportManage.ErrReport(this, "形態素解析に失敗しました:" + e.Message + "\ttext:" + txt);
            }

            return(r);
        }
Beispiel #9
0
        public override bool Check(string txt)
        {
            DateTime dt;

            if (StartDate == null && EndDate == null)
            {
                return(false);
            }

            if (DateTime.TryParse(txt, out dt))
            {
                if (StartDate == null && EndDate != null)
                {
                    if (dt < EndDate)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (StartDate != null && EndDate != null)
                {
                    if (dt >= StartDate && dt < EndDate)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    if (dt >= StartDate)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else
            {
                if (ErrReport)
                {
                    ReportManage.ErrReport(this, "DateTime型のキャストに失敗:" + txt);
                }
                return(false);
            }

//            return base.Check(txt);
        }
Beispiel #10
0
        public IEnumerable <string> ReadAPI()
        {
            var login = this.GetUpperRawler <TwitterLogin>();

            if (login == null)
            {
                ReportManage.ErrReport(this, "TwitterLoginをTweetUserTimelineの上流に配置してください");
                return(new List <string>());
            }

            List <long> list = new List <long>();

            Dictionary <string, object> dic = new Dictionary <string, object>()
            {
                { "cursor", cursor },
                { "count", 5000 }
            };

            if (ScreenName.IsNullOrEmpty() == false)
            {
                dic.Add("screen_name", ScreenName.Convert(this));
            }
            else if (UserId.IsNullOrEmpty() == false)
            {
                dic.Add("user_id", UserId.Convert(this));
            }
            else
            {
                if (ParentUserIdType == RawlerTwitter.ParentUserIdType.ScreenName)
                {
                    dic.Add("screen_name", GetText());
                }
                else if (ParentUserIdType == RawlerTwitter.ParentUserIdType.UserId)
                {
                    dic.Add("user_id", GetText());
                }
            }

            var result = login.Token.Followers.Ids(dic);

            foreach (var item in result.Result)
            {
                list.Add(item);
            }
            if (result.NextCursor > 0)
            {
                cursor = result.NextCursor;
            }
            else
            {
                cursor = -1;
            }


            return(list.Select(n => n.ToString()).ToList());
        }
Beispiel #11
0
        public override bool Check(string txt)
        {
            int dt;

            if (Start == null && End == null)
            {
                return(false);
            }

            if (int.TryParse(txt, out dt))
            {
                if (Start == null && End != null)
                {
                    if (dt < End)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (Start != null && End != null)
                {
                    if (dt >= Start && dt < End)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    if (dt >= Start)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else
            {
                if (ErrReport)
                {
                    ReportManage.ErrReport(this, "int型のキャストに失敗:" + txt);
                }
                return(false);
            }

            //            return base.Check(txt);
        }
Beispiel #12
0
 public void Run(RawlerBase parent)
 {
     try
     {
         var type  = parent.GetType();
         var field = type.GetRuntimeProperty(PropertyName);
         var text  = RawlerBase.GetText(string.Empty, Child, parent);
         if (field.PropertyType == typeof(string))
         {
             field.SetValue(parent, text, null);
         }
         else if (field.PropertyType == typeof(int))
         {
             int num;
             if (int.TryParse(text, out num))
             {
                 field.SetValue(parent, num, null);
             }
             else
             {
                 ReportManage.ErrReport(parent, "InitTreeで" + PropertyName + "の値をint型に変換に失敗しました");
             }
         }
         else if (field.PropertyType == typeof(double))
         {
             double num;
             if (double.TryParse(text, out num))
             {
                 field.SetValue(parent, num, null);
             }
             else
             {
                 ReportManage.ErrReport(parent, "InitTreeで" + PropertyName + "の値をdouble型に変換に失敗しました");
             }
         }
         else if (field.PropertyType == typeof(bool))
         {
             if (text.ToLower() == "true")
             {
                 field.SetValue(parent, true, null);
             }
             else if (text.ToLower() == "false")
             {
                 field.SetValue(parent, false, null);
             }
             else
             {
                 ReportManage.ErrReport(parent, "InitTreeで" + PropertyName + "の値をbool型に変換に失敗しました。Valueは" + text);
             }
         }
     }
     catch (Exception ex)
     {
         ReportManage.ErrReport(parent, "InitTreeで" + PropertyName + "でエラーが発生しました。" + ex.Message);
     }
 }
Beispiel #13
0
 public override void Run(bool runChildren)
 {
     if (System.DateTime.TryParse(GetText(), out dateTime))
     {
         base.Run(runChildren);
     }
     else
     {
         ReportManage.ErrReport(this, "DateTime.TryParseに失敗しました");
     }
 }
Beispiel #14
0
 public override bool Check(string txt)
 {
     if (CheckText != null && CheckText.Length > 0)
     {
         return(txt.Contains(CheckText));
     }
     else
     {
         ReportManage.ErrReport(this, "SwitchTextNodeオブジェクトでCheckTextの値がありません。");
         return(false);
     }
 }
Beispiel #15
0
        /// <summary>
        /// このクラスでの実行すること。
        /// </summary>
        /// <param name="runChildren"></param>
        public override void Run(bool runChildren)
        {
            if (SouceIterator != null)
            {
                SouceIterator.SetParent(this);
                SouceIterator.Run();

                string target = GetText();
                int    count  = 0;
                if (createOnceFlag == false || createOnce == false)
                {
                    //辞書の作成
                    dic = new Dictionary <string, List <string> >();
                    var wordList = SouceIterator.Texts.GetList().OrderByDescending(n => n.Length).ToArray();
                    foreach (var item in wordList)
                    {
                        List <string> tmpList = new List <string>();
                        if (dic.TryGetValue(item.Substring(0, keyWordLength), out tmpList) == false)
                        {
                            tmpList = new List <string>();
                            dic.Add(item.Substring(0, keyWordLength), tmpList);
                        }
                        tmpList.Add(item);
                    }
                }
                List <string> list = new List <string>();
                foreach (var item in NGram(GetText(), keyWordLength).Distinct())
                {
                    List <string> tmpList = new List <string>();
                    if (dic.TryGetValue(item, out tmpList))
                    {
                        foreach (var item2 in tmpList)
                        {
                            target = GetCount(target, item2, out count);
                            if (count >= MinCount)
                            {
                                for (int i = 0; i < count; i++)
                                {
                                    list.Add(item2);
                                }
                            }
                        }
                    }
                }

                RunChildrenForArray(runChildren, list);
            }
            else
            {
                ReportManage.ErrReport(this, "SouceIteratorがありません");
            }
        }
Beispiel #16
0
        public async override void Run(bool runChildren)
        {
            fileReadCompleted = false;
            string file = FileName.Convert(this);

            if (string.IsNullOrEmpty(file))
            {
                file = GetText();
            }
            if (System.IO.File.Exists(file) == false)
            {
                ReportManage.ErrReport(this, "Fileが見つかりません「" + file + "」");
                return;
            }
            cancellationTokenSource = new CancellationTokenSource();
            var task = Task.Factory.StartNew(() =>
            {
                List <string> list = new List <string>(BlockSize);

                foreach (var item in System.IO.File.ReadLines(FileName.Convert(this)))
                {
                    if (cancellationTokenSource.Token.IsCancellationRequested)
                    {
                        break;
                    }
                    bool flag = true;
                    do
                    {
                        if (q.Count < MaxBlock)
                        {
                            list.Add(item);
                            if (list.Count > BlockSize)
                            {
                                q.Push(list.ToArray());
                                list.Clear();
                            }
                            flag = false;
                            break;
                        }
                        else
                        {
                            Task.Delay(3).Wait();
                        }
                    }while (flag);
                }
                fileReadCompleted = true;
            }, cancellationTokenSource.Token);

            base.Run(runChildren);
        }
Beispiel #17
0
        /// <summary>
        /// ラムダ式作成
        /// </summary>
        /// <param name="source"></param>
        public Func <string, string> CreateLambda(string source)
        {
            CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");

            CompilerParameters cp = new CompilerParameters();

            cp.GenerateInMemory      = true;
            cp.TreatWarningsAsErrors = false;
            cp.ReferencedAssemblies.Add("System.dll");      // Regex
            cp.ReferencedAssemblies.Add("System.Core.dll"); // Extensions

            string source2 = @"
            using System;
            using System.Linq;
            using System.Collections.Generic;

            class FunctionClass{
                 Func<string, string> test = (lambda);
                public Func<string,string> Test { get { return test; } }
            }";

            //入力したもので書き換え。
            source2 = source2.Replace("(lambda)", source);
            //コンパイル
            CompilerResults cr = provider.CompileAssemblyFromSource(cp, source2);

            cr.Errors.OfType <CompilerError>().ToArray();
            //エラー処理
            foreach (CompilerError item in cr.Errors)
            {
                ReportManage.ErrReport(this, item.ToString());
            }
            if (cr.Errors.Count > 0)
            {
                return(null);
            }

            //コンパイルしたアセンブリを取得
            var asm = cr.CompiledAssembly;
            //MainClassクラスのTypeを取得
            Type t = asm.GetType("FunctionClass");

            var instance = Activator.CreateInstance(t);
            var m        = t.GetMember("test");

            var method = t.GetProperty("Test").GetValue(instance, null);

            return((Func <string, string>)method);
        }
Beispiel #18
0
        /// <summary>
        /// このクラスでの実行すること。
        /// </summary>
        /// <param name="runChildren"></param>
        public override void Run(bool runChildren)
        {
            string apiIds = ApiId;

            if (string.IsNullOrEmpty(ApiId))
            {
                apiIds = Rawler.Tool.GlobalVar.GetVar("YahooApiId");
            }
            if (string.IsNullOrEmpty(apiIds))
            {
                Rawler.Tool.ReportManage.ErrReport(this, "YahooApiIdがありません。SetTmpValで指定してください");
                return;
            }
            string apiId   = apiIds.Split(',').OrderBy(n => Guid.NewGuid()).First();
            string baseUrl = "http://jlp.yahooapis.jp/KeyphraseService/V1/extract";
            var    post    = "appid=" + apiId + "&sentence=" + Uri.EscapeUriString(GetText());
            string result  = string.Empty;

            try
            {
                System.Net.WebClient wc = new System.Net.WebClient();
                wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                wc.Encoding = Encoding.UTF8;
                result      = wc.UploadString(new Uri(baseUrl), "POST", post);
                wc.Dispose();
            }
            catch (Exception e)
            {
                ReportManage.ErrReport(this, e.Message + "\t" + GetText());
            }
            if (result != string.Empty)
            {
                var root = XElement.Parse(result);
                var ns   = root.GetDefaultNamespace();
                var list = root.Descendants(ns + "Result").Select(n => new KeyphraseResult()
                {
                    Keyphrase = n.Element(ns + "Keyphrase").Value, Score = double.Parse(n.Element(ns + "Score").Value)
                });

                List <string> list2 = new List <string>();
                foreach (var item in list)
                {
                    list2.Add(Codeplex.Data.DynamicJson.Serialize(item));
                }

                base.RunChildrenForArray(runChildren, list2);
            }
        }
Beispiel #19
0
 public override void Run(bool runChildren)
 {
     if (func1 == null)
     {
         CreateFunc();
     }
     if (func1 != null)
     {
         SetText(func1(GetText()));
         RunChildren(runChildren);
     }
     else
     {
         ReportManage.ErrReport(this, "ラムダ式の生成に失敗しました");
     }
 }
Beispiel #20
0
        public override void Run(bool runChildren)
        {
            var queue   = this.GetUpperRawler <ParallelQueue>();
            var dequeue = this.GetUpperRawler <Dequeue>();

            if (queue != null && dequeue != null)
            {
                queue.Completed(dequeue.Text);
            }
            else
            {
                ReportManage.ErrReport(this, "上流にParallelQueue,Dequeueがありません。");
            }

            base.Run(runChildren);
        }
Beispiel #21
0
        /// <summary>
        /// このクラスでの実行すること。
        /// </summary>
        /// <param name="runChildren"></param>
        public override void Run(bool runChildren)
        {
            if (this.Parent == null)
            {
                ReportManage.ErrReport(this, "親クラスがありません。");
                return;
            }
            var xaml = this.Parent.Text;


            try
            {
                var td = TweetData.Parse(xaml);
                this.SetText(td.GetTweetDataElement(DataElement));

                //var obj = System.Xaml.XamlServices.Parse(xaml);
                //if (obj is TweetData)
                //{
                //    var td = obj as TweetData;
                //    var t = td.GetTweetDataElement(DataElement);
                //    t = this.GetText(t);
                //    this.SetText(t);

                var data = this.GetAncestorRawler().OfType <Data>().First();
                if (data != null)
                {
                    data.DataWrite(Attribute, this.GetText(this.text), writeType);
                }
                else
                {
                    ReportManage.ErrReport(this, "上流にDataクラスがありません。");
                }


                //    base.Run(runChildren);
                //}
                //else
                //{
                //    ReportManage.ErrReport(this, "TweetDataの解釈に失敗しました。");
                //}
            }
            catch
            {
                ReportManage.ErrReport(this, "TweetDataの解釈に失敗しました。");
            }
        }
Beispiel #22
0
        public override void RunBatch(IEnumerable <string> list)
        {
            var login = this.GetUpperRawler <TwitterLogin>();

            if (login == null)
            {
                ReportManage.ErrUpperNotFound <TwitterLogin>(this);
            }
            string[] list1 = null;
            bool     flag  = true;

            do
            {
                flag = true;
                try
                {
                    if (ParentUserIdType == ParentUserIdType.ScreenName)
                    {
                        var l = login.Token.Users.Lookup(list);
                        list1 = l.Select(n => Codeplex.Data.DynamicJson.Serialize(n)).ToArray();
                    }
                    else
                    {
                        long[] longList = null;
                        try
                        {
                            longList = list.Select(n => long.Parse(n)).ToArray();
                        }
                        catch (Exception ex)
                        {
                            ReportManage.ErrReport(this, "tweetIdが数値ではありません。" + ex.Message + "\t" + list.JoinText(","));
                        }
                        var l = login.Token.Users.Lookup(longList);
                        list1 = l.Select(n => Codeplex.Data.DynamicJson.Serialize(n)).ToArray();
                    }
                }
                catch (Exception ex1)
                {
                    ReportManage.ErrReport(this, ex1.Message);
                    flag = false;
                    System.Threading.Thread.Sleep(TimeSpan.FromMinutes(3));
                }
            } while (flag);
            base.RunBatch(list1);
        }
Beispiel #23
0
 public static void AddParameterObjcet(IGroupParameterValue obj)
 {
     if (parameterDic.ContainsKey(obj.Group))
     {
         if (parameterDic[obj.Group].Where(n => n.ParameterName == obj.ParameterName).Any())
         {
             ReportManage.ErrReport(null, "RawlerRunMangeのAddParameterObjcetですでに登録済みのキーを再登録します。");
         }
         parameterDic[obj.Group].Add(obj);
     }
     else
     {
         parameterDic.Add(obj.Group, new List <IGroupParameterValue>()
         {
             obj
         });
     }
 }
Beispiel #24
0
 /// <summary>
 /// 実行。
 /// </summary>
 public void Run()
 {
     Init.Run(this);
     if (enable)
     {
         try
         {
             OnBeginRunEvent();
             Run(true);
             Completed();
             OnEndRunEvent();
         }
         catch (Exception e)
         {
             ReportManage.ErrReport(this, e.Message);
         }
     }
 }
Beispiel #25
0
 public void Enqueue(string val)
 {
     if (IsSingle)
     {
         if (completedHash.Contains(val) == false)
         {
             queue.Post(val);
         }
         else
         {
             ReportManage.ErrReport(this, val + "は既に完了済なので追加できません。");
         }
     }
     else
     {
         queue.Post(val);
     }
 }
Beispiel #26
0
        /// <summary>
        /// このクラスでの実行すること。
        /// </summary>
        /// <param name="runChildren"></param>
        public override void Run(bool runChildren)
        {
            if (Text2Tree == null)
            {
                ReportManage.ErrReport(this, "Text2Treeが空です。実行にはText2Treeが必要です。");
                return;
            }
            Text2Tree.SetParent(this);
            string t = RawlerBase.GetText(this.parent.Text, Text2Tree, this);

            var result = Compute(GetText(), t);

            if (result <= maxDistance)
            {
                SetText(result.ToString());

                base.Run(runChildren);
            }
        }
Beispiel #27
0
        public static void RunRawler(string xaml)
        {
            if (isBusy)
            {
                MessageBox.Show("実行中です");
                return;
            }
            string err    = string.Empty;
            var    rawler = Rawler.Tool.RawlerBase.Parse(xaml, out err);

            if (rawler != null)
            {
                try
                {
                    ReportManage.ResetRowCount();
                    //       rowCount = 0;
                    rawler.SetParent();
                    startDate = DateTime.Now;
                    foreach (var item in rawler.GetConectAllRawler())
                    {
                        item.BeginRunEvent += (o, arg) =>
                        {
                            tokenSource.Token.ThrowIfCancellationRequested();
                        };
                    }
                    isBusy = true;
                    Task.Factory.StartNew(() => rawler.Run(), tokenSource.Token).ContinueWith((t) => { StopWatch(); isBusy = false; });
                }
                catch (OperationCanceledException oce)
                {
                    ReportManage.ErrReport(new RawlerBase(), "キャンセルされました");
                    MessageBox.Show("キャンセルされました");
                }
                catch (Exception ex)
                {
                    ReportManage.ErrReport(new RawlerBase(), ex.Message);
                }
            }
            else
            {
                Rawler.Tool.ReportManage.ErrReport(null, err);
            }
        }
        public override void Run(bool runChildren)
        {
            RawlerLib.Timer.StopWatch.Write("RawlerAutoNextLink urlListCreate");
            urlList = new System.Collections.Concurrent.ConcurrentBag <string>();
            RawlerLib.Timer.StopWatch.Write("RawlerAutoNextLink  autoNextLink.Run");

            autoNextLink.Run();
            RawlerLib.Timer.StopWatch.Write("RawlerAutoNextLink  autoNextLink.Run End");

            var page = this.GetUpperRawler <Page>();

            if (page != null)
            {
                if (maxCount > count)
                {
                    var url     = page.GetCurrentUrl();
                    Uri url_uri = new Uri(url);
                    if (urlList.Any())
                    {
                        var test    = urlList.Distinct().Where(n => new Uri(n).Host == url_uri.Host && urlHash.Contains(n) == false).ToList();
                        var nextUrl = urlList.Distinct().Where(n => new Uri(n).Host == url_uri.Host && urlHash.Contains(n) == false)
                                      .Select(n => new { url = n, Distance = Rawler.NPL.LevenshteinDistance.Compute(url, n) })
                                      .OrderBy(n => n.Distance);
                        if (nextUrl.Any())
                        {
                            page.PushUrl(nextUrl.First().url);
                            urlHash.Add(nextUrl.First().url);
                            count++;
                        }
                        urlHash.Add(url);
                    }
                    else
                    {
                        ReportManage.ErrReport(this, "NextLinkの取得がありません");
                    }
                }
            }
            RawlerLib.Timer.StopWatch.Write("RawlerAutoNextLink  End");

            base.Run(runChildren);
        }
Beispiel #29
0
        public override void Run(bool runChildren)
        {
            var queue = this.GetUpperRawler <ParallelQueue>();

            if (queue != null)
            {
                if (string.IsNullOrEmpty(Value))
                {
                    queue.Enqueue(GetText());
                }
                else
                {
                    queue.Enqueue(Value);
                }
                base.Run(runChildren);
            }
            else
            {
                ReportManage.ErrReport(this, "上流にParallelQueueがありません。");
            }
        }
Beispiel #30
0
        public CoreTweet.Core.TokensBase GetOAuthTokens()
        {
            if (System.IO.File.Exists(tokenSettingFileName))
            {
                try
                {
                    var t = System.Xaml.XamlServices.Load(tokenSettingFileName);
                    if (t is TokenData)
                    {
                        var td = t as TokenData;

                        token = new Tokens()
                        {
                            AccessToken       = td.AccessToken,
                            AccessTokenSecret = td.AccessTokenSecret,
                            ConsumerKey       = td.ConsumerKey,
                            ConsumerSecret    = td.ConsumerSecret
                        };

                        this.TokenData = t as TokenData;
                    }
                    else
                    {
                        ReportManage.ErrReport(this, tokenSettingFileName + "の形式がおかしいみたいです。");
                        token = null;
                    }
                }
                catch (Exception e)
                {
                    ReportManage.ErrReport(this, tokenSettingFileName + "を開くのに失敗しました" + e.Message);
                    token = null;
                }
            }
            else
            {
                token = null;
            }
            return(token);
        }