Пример #1
0
void test_ResultList::test_setWord() {
  ResultList list;
  QCOMPARE(list.word(), QString{});

  list.setWord("test");
  QCOMPARE(list.word(), QString{"test"});
}
Пример #2
0
ResultList split_by_tokens(const std::basic_string<CharT> &s,
    const std::basic_string<CharT> &tokens, bool keepEmptyParts = true)
{
    if (tokens.length() == 1)
        return split<ResultList>(s, tokens, keepEmptyParts);

    ResultList slist;

    typename std::basic_string<CharT>::size_type start = 0;
    typename std::basic_string<CharT>::size_type pos;

    std::basic_string<CharT> part;

    // If delimiter.empty():
    //   pos = s.find_first_of(delimiter, start);
    // pos will be s.npos.
    while ((pos = s.find_first_of(tokens, start)) != s.npos) { // strtok
        part = s.substr(start, pos - start);

        if (!part.empty() || keepEmptyParts)
            slist.push_back(part);

        start = pos + 1;
    }

    if (start != s.length() || keepEmptyParts)
        slist.push_back(s.substr(start));

    return slist;
}
Пример #3
0
unsigned long SearchTask::getNumberOfResults(ResultList resList)
{
	unsigned long total=0;
	for (ResultList::iterator it=resList.begin(); it!=resList.end(); ++it)
	{
		total+= it->second.size();
	}
	return total;
}
Пример #4
0
ResultList split(const std::basic_string<CharT> &s,
    const std::basic_string<CharT> &delimiter, bool keepEmptyParts = true)
{
    ResultList slist;

    // If delimiter.empty():
    //   pos = s.find(delimiter, start);
    // pos will be 0.
    if (delimiter.empty()) {
        slist.push_back(s);
        return slist;
    }


    typename std::basic_string<CharT>::size_type start = 0;
    typename std::basic_string<CharT>::size_type pos;

    std::basic_string<CharT> part;

    if (delimiter.length() == 1) {
        CharT ch = delimiter[0];

        // Hope that:
        //   find(std::basic_string<CharT>, CharT ch)
        // will be faster than:
        //   find(std::basic_string<CharT>, std::basic_string<CharT>)
        while ((pos = s.find(ch, start)) != s.npos) { // Use strchr/wcschr instead?
            part = s.substr(start, pos - start);

            if (!part.empty() || keepEmptyParts)
                slist.push_back(part);

            start = pos + delimiter.length();
        }
    } else {
        while ((pos = s.find(delimiter, start)) != s.npos) { // Use strstr/wcsstr instead?
            part = s.substr(start, pos - start);

            if (!part.empty() || keepEmptyParts)
                slist.push_back(part);

            start = pos + delimiter.length();
        }
    }

    if (start != s.length() || keepEmptyParts)
        slist.push_back(s.substr(start));

    return slist;
}
Пример #5
0
inline ResultList split(const std::basic_string<CharT> &s, CharT ch, bool keepEmptyParts = true)
{
#if 0
    ResultList slist;

    std::basic_istringstream<CharT> ss(s);
    std::basic_string<CharT> item;
    while (std::getline(ss, item, ch))
        slist.push_back(item);

    return slist;
#endif

    return split<ResultList>(s, std::basic_string<CharT>(1, ch), keepEmptyParts);
}
Пример #6
0
void test_ResultList::test_appendResult() {
  ResultList list;
  QCOMPARE(list.rowCount(), 0);

  list.appendResult(Definition{"word", "text"});
  QCOMPARE(list.rowCount(), 0);

  list.setWord("word");

  list.appendResult(Definition{"word", "text"});
  QCOMPARE(list.rowCount(), 1);

  list.appendResult(Definition{"WORD", "text"});
  QCOMPARE(list.rowCount(), 2);
}
Пример #7
0
SearchProvider::ResultList IcecastSearchProvider::Search(int id, const QString& query) {
  IcecastBackend::StationList stations = backend_->GetStations(query);
  ResultList ret;

  const QStringList tokens = TokenizeQuery(query);

  foreach (const IcecastBackend::Station& station, stations) {
    if (ret.count() > 3)
      break;

    Result result(this);
    result.type_ = globalsearch::Type_Stream;
    result.metadata_ = station.ToSong();
    result.match_quality_ = MatchQuality(tokens, station.name);
    ret << result;
  }

  return ret;
}
Пример #8
0
void test_ResultList::test_rowCount() {
  ResultList list;
  QCOMPARE(list.rowCount(), 0);

  list.appendResult(Definition{});
  QCOMPARE(list.rowCount(), 1);

  list.appendResult(Definition{});
  QCOMPARE(list.rowCount(), 2);

  list.setWord("test");
  QCOMPARE(list.rowCount(), 0);
}
SimpleSPARQLQuery::Value
SimpleSPARQLQuery::singleResultQuery(QueryType type,
                                     QString query, QString binding)
{
    SimpleSPARQLQuery q(type, query);
    ResultList results = q.execute();
    if (!q.isOK()) {
        cerr << "SimpleSPARQLQuery::singleResultQuery: ERROR: "
             << q.getErrorString() << endl;
        return Value();
    }
    if (results.empty()) {
        return Value();
    }
    for (int i = 0; i < results.size(); ++i) {
        if (results[i].find(binding) != results[i].end() &&
            results[i][binding].type != NoValue) {
            return results[i][binding];
        }
    }
    return Value();
}
Пример #10
0
// Test if a discid that do not exist in the musicbrainz database
// generates an empty result.
TEST_F(MusicBrainzClientTest, DiscIdNotFound) {
  QByteArray data =
      "<?xml version=\"1.0\" encoding=\"UTF-8\"?><error><text>Not "
      "Found</text><text>For usage, please see: "
      "http://musicbrainz.org/development/mmd</text></error>";

  // Create a MusicBrainzClient instance with mock_network_.
  MusicBrainzClient musicbrainz_client(nullptr, mock_network_.get());

  // Hook the data as the response to a query of a given type.
  QMap<QString, QString> params;
  params["inc"] = "artists+recordings";
  MockNetworkReply* discid_reply =
      mock_network_->ExpectGet("discid", params, 200, data);

  // Set up a QSignalSpy which stores the result.
  QSignalSpy spy(&musicbrainz_client,
                 SIGNAL(Finished(const QString&, const QString,
                                 const MusicBrainzClient::ResultList&)));
  ASSERT_TRUE(spy.isValid());
  EXPECT_EQ(0, spy.count());

  // Start the request and get a result. The argument doesn't matter
  // in the test.
  musicbrainz_client.StartDiscIdRequest("fooDiscid");
  discid_reply->Done();
  QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  EXPECT_EQ(1, spy.count());

  QList<QVariant> result = spy.takeFirst();
  QString artist = result.takeFirst().toString();
  QString album = result.takeFirst().toString();
  ResultList tracks = result.takeFirst().value<ResultList>();

  // Check that title and artist are empty, and that there are zero tracks.
  EXPECT_TRUE(artist.isEmpty());
  EXPECT_TRUE(album.isEmpty());
  EXPECT_EQ(0, tracks.count());
}
Пример #11
0
// For a recording with multiple releases, we should get them all.
TEST_F(MusicBrainzClientTest, ParseTrackWithMultipleReleases) {
  QByteArray data =
      ReadDataFromFile(":testdata/recording_with_multiple_releases.xml");
  ASSERT_FALSE(data.isEmpty());

  const int expected_number_of_releases = 7;

  // Create a MusicBrainzClient instance with mock_network_.
  MusicBrainzClient musicbrainz_client(nullptr, mock_network_.get());

  // Hook the data as the response to a query of a given type.
  QMap<QString, QString> params;
  params["inc"] = "artists+releases+media";
  MockNetworkReply* discid_reply =
      mock_network_->ExpectGet("recording", params, 200, data);

  QSignalSpy spy(&musicbrainz_client,
                 SIGNAL(Finished(int, const MusicBrainzClient::ResultList&)));
  ASSERT_TRUE(spy.isValid());
  EXPECT_EQ(0, spy.count());

  // Start the request and get a result.
  // The mbid argument doesn't matter in the test.
  const int sent_id = 0;
  musicbrainz_client.Start(sent_id, QStringList() << "fooMbid");
  discid_reply->Done();
  QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  EXPECT_EQ(1, spy.count());

  QList<QVariant> result = spy.takeFirst();
  int id = result.takeFirst().toInt();
  EXPECT_EQ(sent_id, id);

  ResultList tracks = result.takeFirst().value<ResultList>();
  EXPECT_EQ(expected_number_of_releases, tracks.count());
}
SimpleSPARQLQuery::ResultList
SimpleSPARQLQuery::Impl::executeFor(QString modelUri)
{
    ResultList list;
    librdf_query *query;

#ifdef DEBUG_SIMPLE_SPARQL_QUERY
    static std::map<QString, int> counter;
    if (counter.find(m_query) == counter.end()) counter[m_query] = 1;
    else ++counter[m_query];
    std::cerr << "Counter for this query: " << counter[m_query] << std::endl;
    std::cerr << "Base URI is: \"" << modelUri << "\"" << std::endl;
#endif

    {
        Profiler p("SimpleSPARQLQuery: Prepare LIBRDF query");
        query = librdf_new_query
            (m_redland->getWorld(), "sparql", NULL,
             (const unsigned char *)m_query.toUtf8().data(), NULL);
    }
    
    if (!query) {
        m_errorString = "Failed to construct query";
        return list;
    }

    librdf_query_results *results;
    {
        Profiler p("SimpleSPARQLQuery: Execute LIBRDF query");
        results = librdf_query_execute(query, m_redland->getModel(modelUri));
    }

    if (!results) {
        m_errorString = "RDF query failed";
        librdf_free_query(query);
        return list;
    }

    if (!librdf_query_results_is_bindings(results)) {
        m_errorString = "RDF query returned non-bindings results";
        librdf_free_query_results(results);
        librdf_free_query(query);
        return list;
    }
    
    int resultCount = 0;
    int resultTotal = librdf_query_results_get_count(results); // probably wrong
    m_cancelled = false;

    while (!librdf_query_results_finished(results)) {

        int count = librdf_query_results_get_bindings_count(results);

        KeyValueMap resultmap;

        for (int i = 0; i < count; ++i) {

            const char *name =
                librdf_query_results_get_binding_name(results, i);

            if (!name) {
                std::cerr << "WARNING: Result " << i << " of query has no name" << std::endl;
                continue;
            }

            librdf_node *node =
                librdf_query_results_get_binding_value(results, i);

            QString key = (const char *)name;

            if (!node) {
#ifdef DEBUG_SIMPLE_SPARQL_QUERY
                std::cerr << i << ". " << key << " -> (nil)" << std::endl;
#endif
                resultmap[key] = Value();
                continue;
            }

            ValueType type = LiteralValue;
            QString text;

            if (librdf_node_is_resource(node)) {

                type = URIValue;
                librdf_uri *uri = librdf_node_get_uri(node);
                const char *us = (const char *)librdf_uri_as_string(uri);

                if (!us) {
                    std::cerr << "WARNING: Result " << i << " of query claims URI type, but has null URI" << std::endl;
                } else {
                    text = us;
                }

            } else if (librdf_node_is_literal(node)) {

                type = LiteralValue;

                const char *lit = (const char *)librdf_node_get_literal_value(node);
                if (!lit) {
                    std::cerr << "WARNING: Result " << i << " of query claims literal type, but has no literal" << std::endl;
                } else {
                    text = lit;
                }

            } else if (librdf_node_is_blank(node)) {

                type = BlankValue;

                const char *lit = (const char *)librdf_node_get_literal_value(node);
                if (lit) text = lit;

            } else {

                cerr << "SimpleSPARQLQuery: LIBRDF query returned unknown node type (not resource, literal, or blank)" << endl;
            }

#ifdef DEBUG_SIMPLE_SPARQL_QUERY
            cerr << i << ". " << key << " -> " << text << " (type " << type << ")" << endl;
#endif

            resultmap[key] = Value(type, text);

//            librdf_free_node(node);
        }

        list.push_back(resultmap);

        librdf_query_results_next(results);

        resultCount++;

        if (m_reporter) {
            if (resultCount >= resultTotal) {
                if (m_reporter->isDefinite()) m_reporter->setDefinite(false);
                m_reporter->setProgress(resultCount);
            } else {
                m_reporter->setProgress((resultCount * 100) / resultTotal);
            }

            if (m_reporter->wasCancelled()) {
                m_cancelled = true;
                break;
            }
        }
    }

    librdf_free_query_results(results);
    librdf_free_query(query);

#ifdef DEBUG_SIMPLE_SPARQL_QUERY
    SVDEBUG << "SimpleSPARQLQuery::executeDatastore: All results retrieved (" << resultCount << " of them)" << endl;
#endif

    return list;
}
Пример #13
0
// Test if MusicBrainzClient::StartDiscIdRequest() parses a discid
// correctly.
TEST_F(MusicBrainzClientTest, ParseDiscID) {
  QByteArray data = ReadDataFromFile(":testdata/discid_2cd.xml");
  ASSERT_FALSE(data.isEmpty());

  // The following are the expected values given for the test file
  // discid_2cd.xml. The discid corresponds to the 2nd disc in the
  // set. The test file contains two releases but we only parse the first.
  const QString expected_artist = "Symphony X";
  const QString expected_title = "Live on the Edge of Forever";
  const int expected_number_of_tracks = 6;

  // Create a MusicBrainzClient instance with mock_network_.
  MusicBrainzClient musicbrainz_client(nullptr, mock_network_.get());

  // Hook the data as the response to a query of a given type.
  QMap<QString, QString> params;
  params["inc"] = "artists+recordings";
  MockNetworkReply* discid_reply =
      mock_network_->ExpectGet("discid", params, 200, data);

  // Set up a QSignalSpy which stores the result.
  QSignalSpy spy(&musicbrainz_client,
                 SIGNAL(Finished(const QString&, const QString,
                                 const MusicBrainzClient::ResultList&)));
  ASSERT_TRUE(spy.isValid());
  EXPECT_EQ(0, spy.count());

  // Start the request and get a result. The argument doesn't matter
  // in the test. It is here set to the discid of the requested disc.
  musicbrainz_client.StartDiscIdRequest("lvcH9_vbw_rJAbXieTOo1CbyNmQ-");
  discid_reply->Done();
  QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  EXPECT_EQ(1, spy.count());

  QList<QVariant> result = spy.takeFirst();
  QString artist = result.takeFirst().toString();
  QString album = result.takeFirst().toString();
  ResultList tracks = result.takeFirst().value<ResultList>();

  // Check that title and artist are correct.
  EXPECT_EQ(expected_artist, artist);
  EXPECT_EQ(expected_title, album);

  // Check that we get the correct number of tracks, i.e. that the
  // correct disc is chosen in a multi-disc release.
  EXPECT_EQ(expected_number_of_tracks, tracks.count());

  // Check that the tracks is ordered by track number in ascending
  // order.
  for (int i = 0; i < tracks.count(); ++i) {
    EXPECT_EQ(i + 1, tracks[i].track_);
  }

  // Check some track information.
  EXPECT_EQ("Smoke and Mirrors", tracks[0].title_);
  EXPECT_EQ(1, tracks[0].track_);
  EXPECT_EQ(394600, tracks[0].duration_msec_);

  EXPECT_EQ("Church of the Machine", tracks[1].title_);
  EXPECT_EQ(2, tracks[1].track_);
  EXPECT_EQ(441866, tracks[1].duration_msec_);
}
Пример #14
0
float ScalarImportance
  ::estimateNormalizationConstant(const boost::shared_ptr<RandomSequence> &r,
                                  const boost::shared_ptr<const Scene> &scene,
                                  const boost::shared_ptr<ShadingContext> &context,
                                  const boost::shared_ptr<PathMutator> &mutator,
                                  const size_t n,
                                  FunctionAllocator &allocator,
                                  PathSampler::HyperPoint &x,
                                  Path &xPath)
{
  float result = 0;
  Spectrum L;

  // estimate b
  typedef std::vector<PathSampler::HyperPoint> SeedList;
  typedef std::vector<PathSampler::Result> ResultList;
  ResultList resultList;
  SeedList seeds;
  std::vector<float> seedImportance;
  float I;

  // XXX fix this
  PathSampler *sampler = const_cast<PathSampler*>(mutator->getSampler());
  for(size_t i = 0; i < n; ++i)
  {
    PathSampler::constructHyperPoint(*r, x);

    // create a Path
    if(sampler->constructPath(*scene, *context, x, xPath))
    {
      // evaluate the Path
      resultList.clear();
      L = mutator->evaluate(xPath, resultList);

      I = evaluate(x, xPath, resultList);
      result += I;

      seeds.push_back(x);
      seedImportance.push_back(I);
    } // end if

    // free all integrands allocated in this sample
    context->freeAll();
  } // end for i

  // pick a seed
  AliasTable<PathSampler::HyperPoint> aliasTable;
  aliasTable.build(seeds.begin(), seeds.end(),
                   seedImportance.begin(), seedImportance.end());
  x = aliasTable((*r)());
  Path temp;
  sampler->constructPath(*scene, *context, x, temp);

  // copy temp to x
  temp.clone(xPath, allocator);

  // free all integrands that were allocated in the estimate
  context->freeAll();
  
  return result / n;
} // end ScalarImportance::estimateNormalizationConstant()
Пример #15
0
    virtual MICommand & execute()
    {
        if (operation.compare("-list-features") == 0)
        {
            ResultList featureList;
            Result result;
            result.value = featureList.toString();
            results.push_back(result);
        }
        else if (operation.compare("-list-thread-groups") == 0)
        {
            long recursionDepth = 0;
            bool available = false;

            for (const Option & option :options)
            {
                if (option.name.compare("--available") == 0)
                {
                    available = true;
                }
                else if (option.name.compare("--recurse") == 0)
                {
                    char * endptr = nullptr;
                    recursionDepth = strtol(option.parameter.c_str(), &endptr, 10);
                    recursionDepth = std::max(recursionDepth, 1L);
                }
            }

            if (parameters.empty() == 1)
            {
                ResultList groups;
                for (const MIInterpreter::MITargets::value_type & ptarget : interpreter.getTargets())
                {
                    ResultTuple group;
                    group.push_back(Result("id", CString(ptarget.second->getThreadGroup())));
                    group.push_back(Result("type", CString("process")));
                    group.push_back(Result("executable", CString(ptarget.second->getExecutable())));
                    if (ptarget.second->getTarget().GetProcess().IsValid())
                    {
                        lldb::SBProcess process = ptarget.second->getTarget().GetProcess();
                        group.push_back(Result("num_children", CString(process.GetNumThreads())));
                    }
                    groups.push_back(group);
                }
                results.push_back(Result("groups", groups));
            }
            else if (parameters.size() == 1)
            {
                ResultList threads;
                //todo
                results.push_back(Result("threads", threads));
            }
            else
            {
                ResultList groups;
                for (const std::string & parameter : parameters)
                {
                    MITarget * ptarget = interpreter.findTarget(parameter);
                    if (ptarget)
                    {
                        ResultTuple group;
                        group.push_back(Result("id", CString(ptarget->getThreadGroup())));
                        group.push_back(Result("type", CString("process")));
                        group.push_back(Result("type", CString(ptarget->getTarget().GetExecutable().GetFilename())));
                        if (ptarget->getTarget().GetProcess().IsValid())
                        {
                            lldb::SBProcess process = ptarget->getTarget().GetProcess();
                            group.push_back(Result("num_children", CString(process.GetNumThreads())));
                        }
                        groups.push_back(group);
                    }
                }
                results.push_back(Result("groups", groups));
            }
        }
        return *this;
    }