Package it.unimi.dsi.fastutil.longs

Examples of it.unimi.dsi.fastutil.longs.LongOpenHashSet


            this.matcher = matcher;
        }

        @Override
        public LongSet select(TestUser user) {
            LongSet items = new LongOpenHashSet();
            SparseVector vec = user.getTestRatings();
            for (VectorEntry e: vec) {
                if (matcher.matches(e.getValue())) {
                    items.add(e.getKey());
                }
            }
            return items;
        }
View Full Code Here


            this.selectorTwo = selectorTwo;
        }

        @Override
        public LongSet select(TestUser user) {
            LongSet items = new LongOpenHashSet(selectorOne.select(user));
            items.addAll(selectorTwo.select(user));
            return items;
        }
View Full Code Here

    @Test
    public void testUserUserRecommender3() {
        ItemRecommender recommender = rec.getItemRecommender();
        assert recommender != null;

        LongOpenHashSet candidates = new LongOpenHashSet();
        candidates.add(6);
        candidates.add(7);
        candidates.add(8);
        candidates.add(9);

        List<ScoredId> recs = recommender.recommend(1, candidates);
        assertTrue(recs.isEmpty());

        candidates.clear();
        candidates.add(9);
        recs = recommender.recommend(2, candidates);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   containsInAnyOrder(9L));

        candidates.clear();
        candidates.add(6);
        candidates.add(7);
        candidates.add(8);
        recs = recommender.recommend(2, candidates);
        assertTrue(recs.isEmpty());

        candidates.add(9);
        recs = recommender.recommend(3, candidates);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   containsInAnyOrder(6L));

        recs = recommender.recommend(4, candidates);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   containsInAnyOrder(9L));

        recs = recommender.recommend(5, candidates);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   containsInAnyOrder(7L));

        candidates.remove(7);
        recs = recommender.recommend(5, candidates);
        assertTrue(recs.isEmpty());

        candidates.add(7);
        recs = recommender.recommend(6, candidates);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   containsInAnyOrder(6L, 7L));

        candidates.remove(9);
        recs = recommender.recommend(6, candidates);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   containsInAnyOrder(6L, 7L));

        candidates.remove(8);
        recs = recommender.recommend(6, candidates);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   containsInAnyOrder(6L, 7L));

        candidates.remove(7);
        recs = recommender.recommend(6, candidates);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   containsInAnyOrder(6L));

        candidates.remove(6);
        recs = recommender.recommend(6, candidates);
        assertTrue(recs.isEmpty());
    }
View Full Code Here

    @Test
    public void testUserUserRecommender4() {
        ItemRecommender recommender = rec.getItemRecommender();
        assert recommender != null;

        LongOpenHashSet candidates = new LongOpenHashSet();
        candidates.add(9);
        List<ScoredId> recs = recommender.recommend(2, -1, candidates, null);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   containsInAnyOrder(9L));

        recs = recommender.recommend(2, 1, candidates, null);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   containsInAnyOrder(9L));

        recs = recommender.recommend(2, 0, candidates, null);
        assertTrue(recs.isEmpty());

        LongOpenHashSet exclude = new LongOpenHashSet();
        exclude.add(9);
        recs = recommender.recommend(2, -1, candidates, exclude);
        assertTrue(recs.isEmpty());

        // FIXME Add tests for default exclude set
        recs = recommender.recommend(5, -1, null, LongSets.EMPTY_SET);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   contains(9L, 7L, 6L, 8L));

        recs = recommender.recommend(5, 5, null, LongSets.EMPTY_SET);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   contains(9L, 7L, 6L, 8L));

        recs = recommender.recommend(5, 4, null, LongSets.EMPTY_SET);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   contains(9L, 7L, 6L, 8L));

        recs = recommender.recommend(5, 3, null, LongSets.EMPTY_SET);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   contains(9L, 7L, 6L));

        recs = recommender.recommend(5, 2, null, LongSets.EMPTY_SET);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   contains(9L, 7L));

        recs = recommender.recommend(5, 1, null, LongSets.EMPTY_SET);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   contains(9L));

        recs = recommender.recommend(5, 0, null, LongSets.EMPTY_SET);
        assertTrue(recs.isEmpty());

        candidates.clear();
        candidates.add(6);
        candidates.add(7);
        recs = recommender.recommend(6, -1, candidates, LongSets.EMPTY_SET);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   containsInAnyOrder(6L, 7L));

        candidates.remove(6);
        recs = recommender.recommend(6, -1, candidates, LongSets.EMPTY_SET);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   contains(7L));

        candidates.remove(7);
        recs = recommender.recommend(6, -1, candidates, LongSets.EMPTY_SET);
        assertTrue(recs.isEmpty());

        candidates.add(6);
        candidates.add(7);
        exclude.add(6);
        recs = recommender.recommend(6, -1, candidates, exclude);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   contains(7L));

        exclude.add(7);
        recs = recommender.recommend(6, -1, candidates, exclude);
        assertTrue(recs.isEmpty());

        exclude.remove(6);
        recs = recommender.recommend(6, -1, candidates, exclude);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   contains(6L));
    }
View Full Code Here

        assertEquals(3, recs.size());
        assertEquals(6, recs.get(0).getId());
        assertEquals(7, recs.get(1).getId());
        assertEquals(9, recs.get(2).getId());

        LongOpenHashSet candidates = new LongOpenHashSet();
        candidates.add(6);
        candidates.add(7);
        candidates.add(8);
        candidates.add(9);
        recs = recommender.recommend(5, candidates);
        assertEquals(3, recs.size());
        assertEquals(6, recs.get(0).getId());
        assertEquals(7, recs.get(1).getId());
        assertEquals(9, recs.get(2).getId());

        candidates.remove(8);
        recs = recommender.recommend(5, candidates);
        assertEquals(3, recs.size());
        assertEquals(6, recs.get(0).getId());
        assertEquals(7, recs.get(1).getId());
        assertEquals(9, recs.get(2).getId());

        candidates.remove(7);
        recs = recommender.recommend(5, candidates);
        assertEquals(2, recs.size());
        assertEquals(6, recs.get(0).getId());
        assertEquals(9, recs.get(1).getId());

        candidates.remove(6);
        recs = recommender.recommend(5, candidates);
        assertEquals(1, recs.size());
        assertEquals(9, recs.get(0).getId());

        candidates.remove(9);
        recs = recommender.recommend(5, candidates);
        assertTrue(recs.isEmpty());

        candidates.add(8);
        recs = recommender.recommend(5, candidates);
        assertTrue(recs.isEmpty());
    }
View Full Code Here

        assertEquals(6, recs.get(0).getId());
        assertEquals(7, recs.get(1).getId());
        assertEquals(9, recs.get(2).getId());
        assertEquals(8, recs.get(3).getId());

        LongOpenHashSet exclude = new LongOpenHashSet();
        exclude.add(9);
        recs = recommender.recommend(6, -1, null, exclude);
        assertEquals(3, recs.size());
        assertEquals(6, recs.get(0).getId());
        assertEquals(7, recs.get(1).getId());
        assertEquals(8, recs.get(2).getId());

        exclude.add(6);
        recs = recommender.recommend(6, -1, null, exclude);
        assertEquals(2, recs.size());
        assertEquals(7, recs.get(0).getId());
        assertEquals(8, recs.get(1).getId());

        exclude.add(8);
        recs = recommender.recommend(6, -1, null, exclude);
        assertEquals(1, recs.size());
        assertTrue(recs.contains(7));
    }
View Full Code Here

    public void testItemItemRecommender3() {
        List<ScoredId> recs = recommender.recommend(1, null);
        assertTrue(recs.isEmpty());


        LongOpenHashSet candidates = new LongOpenHashSet();
        candidates.add(6);
        candidates.add(7);
        candidates.add(8);
        candidates.add(9);
        recs = recommender.recommend(1, candidates);
        assertThat(recs, hasSize(0));

        recs = recommender.recommend(2, null);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   contains(9L));

        candidates.clear();
        candidates.add(7);
        candidates.add(8);
        candidates.add(9);
        recs = recommender.recommend(2, candidates);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   contains(9L));

        candidates.add(6);
        candidates.remove(9);
        recs = recommender.recommend(2, candidates);
        assertThat(recs, hasSize(0));

        recs = recommender.recommend(5, null);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   containsInAnyOrder(9L, 7L, 6L));

        candidates.clear();
        candidates.add(6);
        candidates.add(7);
        recs = recommender.recommend(5, candidates);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   containsInAnyOrder(6L, 7L));

        candidates.clear();
        candidates.add(6);
        candidates.add(9);
        recs = recommender.recommend(5, candidates);
        assertThat(Lists.transform(recs, ScoredIds.idFunction()),
                   containsInAnyOrder(6L, 9L));
    }
View Full Code Here

      System.exit(-1);
    }

    String collectionPath = cmdline.getOptionValue(COLLECTION_OPTION);

    LongOpenHashSet tweetids = new LongOpenHashSet();
    File tweetidsFile = new File(cmdline.getOptionValue(ID_OPTION));
    if (!tweetidsFile.exists()) {
      System.err.println("Error: " + tweetidsFile + " does not exist!");
      System.exit(-1);
    }
    LOG.info("Reading tweetids from " + tweetidsFile);

    FileInputStream fin = new FileInputStream(tweetidsFile);
    BufferedReader br = new BufferedReader(new InputStreamReader(fin));

    String s;
    while ((s = br.readLine()) != null) {
      tweetids.add(Long.parseLong(s));
    }
    br.close();
    fin.close();
    LOG.info("Read " + tweetids.size() + " tweetids.");

    File file = new File(collectionPath);
    if (!file.exists()) {
      System.err.println("Error: " + file + " does not exist!");
      System.exit(-1);
    }

    PrintStream out = new PrintStream(System.out, true, "UTF-8");
    StatusStream stream = new JsonStatusCorpusReader(file);
    Status status;
    while ((status = stream.next()) != null) {
      if (tweetids.contains(status.getId())) {
        out.println(status.getJsonObject().toString());
      }
    }
    stream.close();
    out.close();
View Full Code Here

      System.exit(-1);
    }

    String collectionPath = cmdline.getOptionValue(COLLECTION_OPTION);

    LongOpenHashSet tweetids = new LongOpenHashSet();
    File tweetidsFile = new File(cmdline.getOptionValue(ID_OPTION));
    if (!tweetidsFile.exists()) {
      System.err.println("Error: " + tweetidsFile + " does not exist!");
      System.exit(-1);
    }
    LOG.info("Reading tweetids from " + tweetidsFile);

    FileInputStream fin = new FileInputStream(tweetidsFile);
    BufferedReader br = new BufferedReader(new InputStreamReader(fin));

    String s;
    while ((s = br.readLine()) != null) {
      tweetids.add(Long.parseLong(s));
    }
    br.close();
    fin.close();
    LOG.info("Read " + tweetids.size() + " tweetids.");

    File file = new File(collectionPath);
    if (!file.exists()) {
      System.err.println("Error: " + file + " does not exist!");
      System.exit(-1);
    }

    LongOpenHashSet seen = new LongOpenHashSet();
    TreeMap<Long, String> tweets = Maps.newTreeMap();

    PrintStream out = new PrintStream(System.out, true, "UTF-8");
    StatusStream stream = new JsonStatusCorpusReader(file);
    Status status;
    int cnt = 0;
    while ((status = stream.next()) != null) {
      if (!tweetids.contains(status.getId())) {
        LOG.error("tweetid " + status.getId() + " doesn't belong in collection");
        continue;
      }
      if (seen.contains(status.getId())) {
        LOG.error("tweetid " + status.getId() + " already seen!");
        continue;
      }

      tweets.put(status.getId(), status.getJsonObject().toString());
      seen.add(status.getId());
      cnt++;
    }
    LOG.info("total of " + cnt + " tweets in subcollection.");

    for ( Map.Entry<Long, String> entry : tweets.entrySet()){
View Full Code Here

    if ( indexIterator != null && index.length == 1 && ( documentIterator instanceof AbstractIntersectionDocumentIterator || indexIterator.length < MAX_FLAT_DISJUNCTS ) ) {
      /* This code is a flat, simplified duplication of what a CounterSetupVisitor would do. It is here just for efficiency. */
      numberOfPairs = 0;
      /* Find duplicate terms. We score unique pairs term/index with nonzero frequency, as the standard method would do. */
      final LongOpenHashSet alreadySeen = new LongOpenHashSet();

      for( int i = indexIterator.length; i-- != 0; )
        if ( indexIterator[ i ].frequency() != 0 && alreadySeen.add( indexIterator[ i ].termNumber() ) ) numberOfPairs++;

      if ( numberOfPairs == indexIterator.length ) flatIndexIterator = indexIterator;
      else {
        /* We must compact the array, eliminating zero-frequency iterators. */
        flatIndexIterator = new IndexIterator[ numberOfPairs ];
        alreadySeen.clear();
        for( int i = 0, p = 0; i != indexIterator.length; i++ )
          if ( indexIterator[ i ].frequency() != 0 &&  alreadySeen.add( indexIterator[ i ].termNumber() ) ) flatIndexIterator[ p++ ] = indexIterator[ i ];
      }

      if ( flatIndexIterator.length != 0 ) {
        // Some caching of frequently-used values
        k1TimesBDividedByAverageDocumentSize = k1 * b * flatIndexIterator[ 0 ].index().numberOfDocuments / flatIndexIterator[ 0 ].index().numberOfOccurrences;
View Full Code Here

TOP

Related Classes of it.unimi.dsi.fastutil.longs.LongOpenHashSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.