Example #1
0
        protected void DoWork()
        {
            while (MyAssociations.HaveQueries() && !MyAssociations.IsLimitReached())
            {
                SGF query = MyAssociations.GetQuery();
                QueryAsyncRequest queryWaiter = MyAssociateDataBase.QueryAsyncRequest(query);

                try
                {
                    queryWaiter.Wait();
                }
                catch (ThreadInterruptedException)
                {
                    queryWaiter.Stop();
                    return;
                }

                List <SGF> queryResult = MyDecomposer.Proceed(queryWaiter.GetResult());
                MyAssociations.Associate(query, queryResult);

                try
                {
                    Thread.Sleep(0); //check Interrupted
                }
                catch (ThreadInterruptedException)
                {
                    return;
                }
            }
            if (EAllWorkIsComplete != null)
            {
                EAllWorkIsComplete(); //Generally impossible, but...
            }
        }
Example #2
0
        public Associations Associate(SGF query, List <SGF> queryResult)
        {
            //add new queries
            AddQueriesFromResultsSgf(queryResult);

            //remove old query
            Queries.Remove(query);

            //add graph edges
            var queryDecomposed = query.Decompose();

            foreach (var sgf in queryResult)
            {
                foreach (var msgfTo in sgf.Decompose())
                {
                    foreach (var msgfFrom in queryDecomposed)
                    {
                        Graph.AddEdge(msgfFrom, msgfTo);
                    }
                }
            }

            //update limits
            UnitsLimit.UpdateCurrentValues(
                (uint)Math.Max(QueriesList.Count(), Queries.Count)
                , Graph.GetNodeCount()
                , Graph.GetEdgeCount());

            return(this);
        }
Example #3
0
 public Associations InitAssociations(SGF sgf)
 {
     foreach (var msgf in sgf.Decompose())
     {
         StartNodes.Add(msgf);
     }
     return(AddQueriesFromResultsSgf(new List <SGF> {
         sgf
     }));
 }
Example #4
0
        public static List <SGF> GenQueries(SGF sgf)
        {
            var list = sgf.Decompose();
            var ret  = new List <SGF>();
            {//gen words
                foreach (var msgf in list)
                {
                    ret.Add(
                        new SGF().AggregateFrom(
                            new List <MSGF> {
                        msgf
                    }));
                }
            }
            {//gen pairs
                MSGF a1 = null;
                foreach (var msgf in list)
                {
                    if (a1 != null)
                    {
                        ret.Add(
                            new SGF().AggregateFrom(
                                new List <MSGF> {
                            a1, msgf
                        }.OrderBy(l => l.GetContent())
                                .ToList()));
                    }
                    a1 = msgf;
                }
            }
            {//gen tripples
                MSGF a1 = null, a2 = null;
                foreach (var msgf in list)
                {
                    if (a1 != null && a2 != null)
                    {
                        ret.Add(
                            new SGF().AggregateFrom(
                                new List <MSGF> {
                            a1, a2, msgf
                        }.OrderBy(l => l.GetContent())
                                .ToList()));
                    }
                    a1 = a2;
                    a2 = msgf;
                }
            }
            var rnd = new Random();

            return
                (ret.OrderBy(x => rnd.Next())
                 .Take(Math.Max(3, (ret.Count + 9) / 10))
                 .ToList());
        }
Example #5
0
        public static AssociationsFinder FindAssociationsAsync(SGF sgf)
        {
            var associationsFinder =
                new AssociationsFinder(
                    sgf
                    , new AssociateDataBase()
                    , new Decomposer(true)
                    , new Associations(new Limit(30000)));

            return(associationsFinder.Run());
        }
Example #6
0
        public AssociationsFinder(
            SGF sgf
            , AssociateDataBase associateDataBase
            , Decomposer decomposer
            , Associations associations)
        {
            Sgf = sgf;
            MyAssociateDataBase = associateDataBase;
            MyDecomposer        = decomposer;
            MyAssociations      = associations;

            MyAssociations.InitAssociations(sgf);
        }
 public QueryAsyncRequest QueryAsyncRequest(SGF query)
 {
     lock (RequestSunchronizer)
     {
         try
         {
             Sleeper.Join();
         }
         catch (ThreadStateException) { }
         Sleeper = new Thread(ThreadBody);
         Sleeper.Start();
     }
     return(new QueryAsyncRequest(query));
 }
Example #8
0
        public QueryAsyncRequest(SGF query)
        {
            string searchQuery = query.Decompose().Select(x => x.GetContent()).Aggregate((a, b) => a + " " + b);
            string fullUrl     = BeginUrl + WebUtility.UrlEncode(searchQuery);

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fullUrl);

            InitHttpWebRequest(ref request);

            RequestProcessor = new Thread(() =>
            {
                DoRequest(request);
            });

            RequestProcessor.Start();
        }