Ejemplo n.º 1
0
 /// <summary>
 /// return ner to the opennlp ner pool
 /// </summary>
 /// <param name="parser"></param>
 public static void ReturnOpenNer(OpenNer ner)
 {
     for (var i = 0; i < ners.Count; i++)
     {
         if (ner == ners[i])
         {
             lock (availableNers)
             {
                 availableNers.Add(i);
             }
             break;
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Get a stanford ner from ner pool
 /// </summary>
 /// <returns></returns>
 public static OpenNer GetOpenNer()
 {
     lock (locker)
     {
         lock (availableNers)
         {
             if (availableNers.Count > 0)
             {
                 try
                 {
                     var index = availableNers.First();
                     availableNers.Remove(index);
                     return(ners[index]);
                 }
                 catch (Exception e)
                 {
                     Console.Clear();
                     Console.WriteLine("Ner pool is empty!");
                     Console.WriteLine(availableNers.Count);
                     Console.WriteLine(e.Message);
                     throw e;
                 }
             }
             else if (ners.Count < maxNerNum)
             {
                 if (availableNers.Count == 0)
                 {
                     var ner = new OpenNer();
                     ners.Add(ner);
                     return(ner);
                 }
                 else
                 {
                     var index = availableNers.First();
                     availableNers.Remove(index);
                     return(ners[index]);
                 }
             }
         }
         {
             while (availableNers.Count == 0)
             {
                 Thread.Sleep(10);
             }
             var index = availableNers.First();
             availableNers.Remove(index);
             return(ners[index]);
         }
     }
 }