示例#1
0
    bool timestamp_composite_matcher::skip_missing_stream(std::vector<matcher*> synced, matcher* missing)
    {
        if(!missing->get_active())
            return true;

        frame_holder* synced_frame;

        _frames_queue[synced[0]].peek(&synced_frame);

        auto next_expected = _next_expected[missing];

        auto it = _next_expected_domain.find(missing);
        if (it != _next_expected_domain.end())
        {
            if (it->second != (*synced_frame)->get_frame_timestamp_domain())
            {
                return false;
            }
        }

        //next expected of the missing stream didn't updated yet
        if((*synced_frame)->get_frame_timestamp() > next_expected)
        {
            return false;
        }

        return !are_equivalent((*synced_frame)->get_frame_timestamp(), next_expected, (*synced_frame)->get_stream()->get_framerate());
    }
示例#2
0
    bool timestamp_composite_matcher::are_equivalent(frame_holder & a, frame_holder & b)
    {
        auto a_fps = a->get_stream()->get_framerate();
        auto b_fps = b->get_stream()->get_framerate();

        auto min_fps = std::min(a_fps, b_fps);

        auto ts = extract_timestamps(a, b);

        return  are_equivalent(ts.first, ts.second, min_fps);
    }
示例#3
0
bool DumpXMLAnnotationVisitor::are_equivalent(
      LinguisticGraphEdge currentEdge,
      LinguisticGraphVertex vProcessed,
      LinguisticGraphVertex vNotProcessed,
      const LinguisticGraph& g)
{
  LinguisticGraphEdge refEdge = LinguisticGraphEdge();
  LinguisticGraphInEdgeIt it, it_end;
  boost::tie(it, it_end) = boost::in_edges(vProcessed,g);
  if (it != it_end)
  { 
    refEdge = *it;
  }
  if (refEdge!=LinguisticGraphEdge() 
      && (vProcessed != vNotProcessed)
      && get(vertex_token, g,vProcessed)!=0 
      && get(vertex_token, g,vNotProcessed)!=0 
      &&  Common::Misc::limastring2utf8stdstring(get(vertex_token, g,vProcessed)->stringForm())==Common::Misc::limastring2utf8stdstring(get(vertex_token, g,vNotProcessed)->stringForm()) 
      && source(refEdge,g)==source(currentEdge,g))
  {
    return true;
  }
  if (currentEdge!=DependencyGraphEdge() && source(currentEdge,g)!=vProcessed)
  {
    if (refEdge!=LinguisticGraphEdge())
    { 
      vProcessed = source(*it,g);
    }
    vNotProcessed = source(currentEdge,g);
    boost::tie(it, it_end) = boost::in_edges(vNotProcessed,g);
    if (it != it_end)
    { 
      currentEdge = *it;
    }
    return are_equivalent(currentEdge, vProcessed, vNotProcessed,g);
  }
   return false;
}
示例#4
0
void DumpXMLAnnotationVisitor::examine_edge(LinguisticGraphEdge e,
                                     const LinguisticGraph& g)
{
  COREFSOLVERLOGINIT;
  LDEBUG << "DumpXMLAnnotationVisitor::examine_edge";
  LinguisticGraphVertex v = target(e, g);
  // let process sentences like (...) have automatically tuned (...) where the graph has one token "have_tuned" with one branch "automatically" "tuned" and another one with the following of the sentence
  LinguisticGraphOutEdgeIt it, it_end;
  boost::tie(it, it_end) = boost::out_edges(v,g);  
   if (it == it_end) 
     return;
  // let process sentences where one tag has not been fully determined and there is still two (or more) tag options
  LinguisticGraphVertex v2 = target(m_lastEdge, g);
  if (v2==v)
    return;
  if (m_lastEdge!=LinguisticGraphEdge() && are_equivalent(e, v2, v, g))
    return;
  // begin
  // store this edge for the future tests
  if (get(vertex_token, g,v)!=0)
    m_lastEdge = e;
//   const FsaStringsPool& stringsPool= Common::MediaticData::MediaticData::single().stringsPool(m_language);
  Token* token = get(vertex_token, g, v);
  // processing of cases like "s'y introduire", tokenized as "y s'introduire"
  if (token != 0 && (token->stringForm() == "en" || token->stringForm() =="y"))
  {
    LinguisticGraphOutEdgeIt it, it_end;
    boost::tie(it, it_end) = boost::out_edges(v,g);  
    if (it != it_end)
    { 
      Token* t = get(vertex_token, g,target(*it, g));
      if (t!=0 && Common::Misc::limastring2utf8stdstring(t->stringForm()).substr(0,2)=="s'") 
      {
        m_ostream << "s'";
      }
    }
  }
  // process
  std::set< AnnotationGraphVertex > matches = m_ad->matches("PosGraph",v,"annot");
  if (matches.empty())
  {
    COREFSOLVERLOGINIT;
    LERROR << "DumpXMLAnnotationVisitor::examine_edge No annotation graph vertex matches PoS graph vertex " << v <<  ". This should not happen.";
    return;
  }
  AnnotationGraphVertex av = *matches.begin();
  
  
  
  if (m_ad->hasAnnotation(av, Common::Misc::utf8stdstring2limastring("Coreferent")))
  {
    GenericAnnotation ga = (m_ad->annotation(av,utf8stdstring2limastring("Coreferent")));
    Lima::LinguisticProcessing::Coreferences::CoreferentAnnotation ca;
    try
    {
      ca = ga.value<Lima::LinguisticProcessing::Coreferences::CoreferentAnnotation>();
      ca.outputXml(m_ostream,g,m_ad);
    }
    catch (const boost::bad_any_cast& )
    {
      COREFSOLVERLOGINIT;
      LERROR << "non coreferent annotation"<< LENDL;
    }
  }
  else 
  {
    Token* token = get(vertex_token, g, v);
    if (token != 0)
    {
      std::string s = Common::Misc::limastring2utf8stdstring(token->stringForm());
      // processing of cases like "s'y introduire", tokenized as "y s'introduire"    
      if (s.substr(0,2) == "s'")
      {
        Token* t = get(vertex_token,g,source(e, g));
        if (t!=0 && (Common::Misc::limastring2utf8stdstring(t->stringForm()).substr(0,2)=="en" || Common::Misc::limastring2utf8stdstring(t->stringForm()).substr(0,2)=="y"))
        {
          s = s.substr(2,s.size());
        }
      }
      // processing of cases like "le Canada a-t-il envisagé...", où le mot entre "a" et "envisagé" se retrouverait rejeté après "a_envisagé". Nécessaire de traiter car problématique pour l'évaluation quand il s'agit d'un pronom clitique comme dans ce cas-ci.
      std::string formerMemo = m_memo;
      match_results<std::string::const_iterator> what; 
      string::const_iterator start = s.begin();
      string::const_iterator end = s.end();
      if (regex_search(s, what, regex("_")))
      {
        m_memo = std::string(what[0].second,end) + " ";
        s = std::string(start,what[0].first);
      }
      else m_memo = "";

      m_ostream << formerMemo << s;
      if (token->status().isAlphaPossessive())
      {
        m_ostream << "'s "; 
      }
    }
  }
  m_ostream << " ";
}
示例#5
0
    void composite_matcher::sync(frame_holder f, syncronization_environment env)
    {
        std::stringstream s;
        s <<"SYNC "<<_name<<"--> "<< f->get_stream()->get_stream_type() << " " << f->get_frame_number() << ", "<<std::fixed<< f->get_frame_timestamp()<<"\n";
        LOG_DEBUG(s.str());

        update_next_expected(f);
        auto matcher = find_matcher(f);
        _frames_queue[matcher.get()].enqueue(std::move(f));

        std::vector<frame_holder*> frames_arrived;
        std::vector<librealsense::matcher*> frames_arrived_matchers;
        std::vector<librealsense::matcher*> synced_frames;
        std::vector<librealsense::matcher*> missing_streams;

        do
        {
            auto old_frames = false;

            synced_frames.clear();
            missing_streams.clear();
            frames_arrived_matchers.clear();
            frames_arrived.clear();


            for (auto s = _frames_queue.begin(); s != _frames_queue.end(); s++)
            {
                frame_holder* f;
                if (s->second.peek(&f))
                {
                    frames_arrived.push_back(f);
                    frames_arrived_matchers.push_back(s->first);
                }
                else
                {
                    missing_streams.push_back(s->first);
                }
            }

            if (frames_arrived.size() == 0)
                break;

            frame_holder* curr_sync;
            if (frames_arrived.size() > 0)
            {
                curr_sync = frames_arrived[0];
                synced_frames.push_back(frames_arrived_matchers[0]);
            }

            for (auto i = 1; i < frames_arrived.size(); i++)
            {
                if (are_equivalent(*curr_sync, *frames_arrived[i]))
                {
                    synced_frames.push_back(frames_arrived_matchers[i]);
                }
                else if (is_smaller_than(*frames_arrived[i], *curr_sync))
                {
                    old_frames = true;
                    synced_frames.clear();
                    synced_frames.push_back(frames_arrived_matchers[i]);
                    curr_sync = frames_arrived[i];
                }
                else
                {
                    old_frames = true;
                }
            }

            if (!old_frames)
            {
                for (auto i : missing_streams)
                {
                    if (!skip_missing_stream(synced_frames, i))
                    {
                        synced_frames.clear();
                        break;
                    }
                }
            }

            if (synced_frames.size())
            {
                std::vector<frame_holder> match;
                match.reserve(synced_frames.size());

                for (auto index : synced_frames)
                {
                    frame_holder frame;
                    _frames_queue[index].dequeue(&frame);

                    match.push_back(std::move(frame));
                }

                std::sort(match.begin(), match.end(), [](frame_holder& f1, frame_holder& f2)
                {
                    return f1->get_stream()->get_unique_id()> f2->get_stream()->get_unique_id();
                });


                std::stringstream s;
                s<<"MATCHED: ";
                for(auto&& f: match)
                {
                    auto composite = dynamic_cast<composite_frame*>(f.frame);
                    if(composite)
                    {
                        for (int i = 0; i < composite->get_embedded_frames_count(); i++)
                        {
                            auto matched = composite->get_frame(i);
                            s << matched->get_stream()->get_stream_type()<<" "<<matched->get_frame_timestamp()<<" ";
                        }
                    }
                    else {
                         s<<f->get_stream()->get_stream_type()<<" "<<(double)f->get_frame_timestamp()<<" ";
                    }


                }
                s<<"\n";
                LOG_DEBUG(s.str());
                frame_holder composite = env.source->allocate_composite_frame(std::move(match));
                if (composite.frame)
                {
                    s <<"SYNCED "<<_name<<"--> "<< composite->get_stream()->get_stream_type() << " " << composite->get_frame_number() << ", "<<std::fixed<< composite->get_frame_timestamp()<<"\n";

                    auto cb = begin_callback();
                    _callback(std::move(composite), env);
                }
            }
        } while (synced_frames.size() > 0);
    }