Package org.grouplens.lenskit.data.pref

Examples of org.grouplens.lenskit.data.pref.Preference


                try {
                    PrintWriter writer = closer.register(new PrintWriter(file));
                    Cursor<Rating> ratings = closer.register(eventDAO.streamEvents(Rating.class));
                    for (Rating r: ratings) {
                        writer.printf("%d,%d,", r.getUserId(), r.getItemId());
                        Preference p = r.getPreference();
                        if (p != null) {
                            writer.print(p.getValue());
                        }
                        writer.print(",");
                        long ts = r.getTimestamp();
                        if (ts >= 0) {
                            writer.print(ts);
View Full Code Here


                .setTimestamp(349702)
                .build();
        assertThat(r, notNullValue());
        assertThat(r.getUserId(), equalTo(692L));
        assertThat(r.getItemId(), equalTo(483L));
        Preference pref = r.getPreference();
        assertThat(pref, notNullValue());
        assert pref != null;
        assertThat(pref.getValue(), equalTo(3.5));
        assertThat(pref.getUserId(), equalTo(692L));
        assertThat(pref.getItemId(), equalTo(483L));
        assertThat(r.getTimestamp(), equalTo(349702L));
    }
View Full Code Here

                .setTimestamp(349702)
                .build();
        assertThat(r, notNullValue());
        assertThat(r.getUserId(), equalTo(692L));
        assertThat(r.getItemId(), equalTo(483L));
        Preference pref = r.getPreference();
        assertThat(pref, nullValue());
        assertThat(r.getTimestamp(), equalTo(349702L));
    }
View Full Code Here

        assertThat(data.size(), equalTo(0));
    }

    @Test
    public void testAddPreference() {
        Preference pref = Preferences.make(10, 39, 3.5);
        int idx = bld.add(pref);
        assertThat(idx, equalTo(0));
        assertThat(bld.size(), equalTo(1));
        PackedPreferenceData data = bld.build();
        assertThat(data.size(), equalTo(1));
View Full Code Here

        TableWriter table = CSVWriter.open(file, null);
        try {
            Cursor<Rating> ratings = dao.streamEvents(Rating.class);
            try {
                for (Rating r: ratings) {
                    Preference p = r.getPreference();
                    if (p != null) {
                        row[0] = r.getUserId();
                        row[1] = r.getItemId();
                        if (writeRatings) {
                            row[2] = p.getValue();
                        }
                        table.writeRow(row);
                    }
                }
            } finally {
View Full Code Here

        long count = 0;

        Cursor<Rating> ratings = dao.streamEvents(Rating.class);
        try {
            for (Rating r : ratings) {
                Preference p = r.getPreference();
                if (p != null) {
                    total += p.getValue();
                    count += 1;
                }
            }
        } finally {
            ratings.close();
View Full Code Here

            logger.debug("computing item mean ratings");
            Cursor<Rating> ratings = dao.streamEvents(Rating.class);
            try {
                IdMeanAccumulator accum = new IdMeanAccumulator();
                for (Rating r: ratings) {
                    Preference p = r.getPreference();
                    if (p != null) {
                        accum.put(p.getItemId(), p.getValue());
                    }
                }
                globalMean = accum.globalMean();
                itemMeans = accum.idMeanOffsets(damping);
            } finally {
View Full Code Here

                    timestamps[idx] = r.getTimestamp();
                    keys.setActive(idx, true);
                }
            }

            Preference p = r.getPreference();
            if (p != null) {
                // save the preference
                msv.set(id, p.getValue());
            } else {
                msv.unset(id);
            }
        }
View Full Code Here

        Preconditions.checkNotNull(r, "rating");
        RatingBuilder rb = newBuilder();
        rb.setUserId(r.getUserId())
          .setItemId(r.getItemId())
          .setTimestamp(r.getTimestamp());
        Preference pref = r.getPreference();
        if (pref == null) {
            rb.clearRating();
        } else {
            rb.setRating(pref.getValue());
        }
        return rb;
    }
View Full Code Here

            return true;
        } else if (r1 == null || r2 == null) {
            return false;
        }

        Preference p1 = r1.getPreference();
        Preference p2 = r2.getPreference();
        if (p1 != null && p2 != null) {
            return r1.getUserId() == r2.getUserId()
                    && r1.getItemId() == r2.getItemId()
                    && r1.getTimestamp() == r2.getTimestamp();
        } else if (p1 != null) {
View Full Code Here

TOP

Related Classes of org.grouplens.lenskit.data.pref.Preference

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.