<commit_before>package edu.neu.ccs.pyramid.dataset;

import org.apache.mahout.math.Vector;

import java.io.Serializable;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * Created by chengli on 9/27/14.
 */
public class MultiLabel implements Serializable{
    private static final long serialVersionUID = 2L;
    private Set<Integer> labels;


    public MultiLabel() {
        this.labels = new HashSet<>();
    }

    /**
     *
     * @param vector a binary label vector
     */
    public MultiLabel(Vector vector){
        this();
        for (Vector.Element element:vector.nonZeroes()){
            this.addLabel(element.index());
        }
    }

    public MultiLabel addLabel(int k) {
        this.labels.add(k);
        return this;
    }

    public void removeLabel(int k) {
        if (labels.contains(k)) {
            labels.remove(k);
        }
    }

    public boolean matchClass(int k){
        return labels.contains(k);
    }

    public Set<Integer> getMatchedLabels(){
        return labels;
    }

    public List<Integer> getMatchedLabelsOrdered(){
        return labels.stream().sorted().collect(Collectors.toList());
    }<commit_msg>add method flip<commit_after>package edu.neu.ccs.pyramid.dataset;

import org.apache.mahout.math.Vector;

import java.io.Serializable;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * Created by chengli on 9/27/14.
 */
public class MultiLabel implements Serializable{
    private static final long serialVersionUID = 2L;
    private Set<Integer> labels;


    public MultiLabel() {
        this.labels = new HashSet<>();
    }

    /**
     *
     * @param vector a binary label vector
     */
    public MultiLabel(Vector vector){
        this();
        for (Vector.Element element:vector.nonZeroes()){
            this.addLabel(element.index());
        }
    }

    public MultiLabel addLabel(int k) {
        this.labels.add(k);
        return this;
    }

    public void removeLabel(int k) {
        if (labels.contains(k)) {
            labels.remove(k);
        }
    }

    public void flipLabel(int k){
        if (labels.contains(k)){
            labels.remove(k);
        } else {
            labels.add(k);
        }
    }

    public boolean matchClass(int k){
        return labels.contains(k);
    }

    public Set<Integer> getMatchedLabels(){
        return labels;
    }

    public List<Integer> getMatchedLabelsOrdered(){
        return labels.stream().sorted().collect(Collectors.toList());
    }
{'fraction_non_alphanumeric': 0.11917293233082707, 'fraction_numerical': 0.004511278195488722, 'mean_word_length': 2.385496183206107, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6099652', 'n_tokens_mistral': 817, 'n_tokens_neox': 792, 'n_words': 179}