public List <List <route> > searchPaths(string from, string to)
        {
            int fromId = unitOfWork.getAirportsRepository().getAirportIdByAirport(from);
            int toId   = unitOfWork.getAirportsRepository().getAirportIdByAirport(to);

            graph  = new VariableGraph();
            yenAlg = new YenTopKShortestPathsAlg(graph);
            List <Path> shortest_paths_list = new List <Path>();

            shortest_paths_list = yenAlg.get_shortest_paths(
                graph.get_airport(fromId), graph.get_airport(toId), 10);

            List <List <route> > result = new List <List <route> >();

            foreach (Path path in shortest_paths_list)
            {
                result.Add(path.getRoutes());
            }

            List <List <route> > temmpAllRoutes = result;



            allRoutes = new List <List <route> >();

            foreach (List <route> a in temmpAllRoutes)
            {
                allRoutes.Add(a);
            }
            return(allRoutes);
        }
        public string predictAccentsWithMultiMatches(string sentence, int nResults, bool getWeight = true)
        {
            LinkedHashMap <string, double> output = new LinkedHashMap <string, double>();
            string @in         = Utils.normaliseString(sentence);
            string lowercaseIn = @in.ToLower();

            string[] words = ("0 " + lowercaseIn + " 0").Split(' ');
            Graph    graph = new VariableGraph();
            Dictionary <int, string> idxWordMap = new Dictionary <int, string>();
            int index = 0;

            int[] numberP = new int[words.Length];

            string[,] possibleChange = new string[words.Length, maxp];

            int[,] indices = new int[words.Length, maxp];
            int nVertex = 0;

            index = buildGraph(words, graph, idxWordMap, index, numberP, possibleChange, indices, nVertex);

            //Yen Algorithm for kShortestPaths
            YenTopKShortestPathsAlg yenAlg = new YenTopKShortestPathsAlg(graph);
            List <Accent.KShortestPaths.Model.Path> shortest_paths_list = yenAlg.get_shortest_paths(graph.get_vertex(0), graph.get_vertex(index - 1), nResults);

            foreach (Accent.KShortestPaths.Model.Path path in shortest_paths_list)
            {
                List <BaseVertex> pathVertex = path.get_vertices();
                string            text       = "";
                for (int i = 1; i < pathVertex.Count - 1; i++)
                {
                    BaseVertex vertext = pathVertex[i];
                    text += idxWordMap[vertext.get_id()] + " ";
                    if (text.Contains("đầm dáng"))
                    {
                        text.Replace("đầm dáng", "đảm đang");
                    }
                    if (text.Contains("chào bán"))
                    {
                        text = Regex.Replace(text, "chào bán", "chào bạn");
                    }
                    if (text.Contains("bị đầu tay"))
                    {
                        text = Regex.Replace(text, "bị đầu tay", "bị đau tay");
                    }
                    if (text.Contains("tay tôi bị đầu"))
                    {
                        text = Regex.Replace(text, "tay tôi bị đầu", "tay tôi bị đau");
                    }
                }
                output.Add(processOutput(@in, text.Trim()), path.get_weight());
            }

            // Không lấy trọng số đo lường cho các trường hợp thêm dấu.
            if (!getWeight)
            {
                return(output.ToString2());
            }

            return(output.ToString());
        }
Ejemplo n.º 3
0
 /**
  * Constructor 2
  *
  * @param graph
  * @param sourceVertex
  * @param targetVertex
  */
 public YenTopKShortestPathsAlg(BaseGraph graph,
                                BaseVertex sourceVertex, BaseVertex targetVertex)
 {
     if (graph == null)
     {
         throw new System.ArgumentException("A NULL graph object occurs!");
     }
     this.graph        = new VariableGraph((Graph)graph);
     this.sourceVertex = sourceVertex;
     this.targetVertex = targetVertex;
     Init();
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Constructor 2
 /// </summary>
 /// <param name="graph"> </param>
 /// <param name="source_vt"> </param>
 /// <param name="target_vt"> </param>
 public YenTopKShortestPathsAlg(BaseGraph graph, BaseVertex source_vt, BaseVertex target_vt)
 {
     if (graph == null)
     {
         throw new System.ArgumentException("A NULL graph object occurs!");
     }
     //
     _graph         = new VariableGraph((Graph)graph);
     _source_vertex = source_vt;
     _target_vertex = target_vt;
     //
     _init();
 }