<commit_before>package org.openbel.framework.test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import org.openbel.framework.api.AnnotationFilterCriteria;
import org.openbel.framework.api.KamStoreException;
import org.openbel.framework.common.InvalidArgument;
import org.openbel.framework.internal.KAMCatalogDao.AnnotationFilter;
import org.openbel.framework.internal.KAMStoreDaoImpl.AnnotationType;
import org.openbel.framework.internal.KAMStoreDaoImpl.BelStatement;
import org.openbel.framework.api.Kam.KamEdge;

/**
 * Test filtering of statements by annotation on the KAM Edge:
 *
 * <p>
 * Small Corpus document
 * <br/>
 * id: <tt>{@value #TEST_EDGE_ID}</tt><br/>
 * edge label: <tt>proteinAbundance(78) actsIn gtpBoundActivity(proteinAbundance(78))</tt>
 * </p>
 *
 * @author <NAME> &lt;<EMAIL>&gt;
 */
public class AnnotationFilterIT extends KAMStoreTest {
    private static final int TEST_EDGE_ID = 1973;

    @Before
    public void setup() {
        setupKamStore(Constants.SMALL_CORPUS_KAM_NAME);
    }

    @After
    public void teardown() {
        teardownKamStore();
    }

    @Test
    public void includeOnlyFilter() {
        AnnotationFilter filter = testKam.getKamInfo().createAnnotationFilter();

        AnnotationType cellLine = findAnnotationType("CellLine");
        if (cellLine == null) {
            fail("The CellLine annotation type is not in KAM.");
        }

        AnnotationFilterCriteria criteria = new AnnotationFilterCriteria(cellLine);
        criteria.setInclude(true);
        criteria.getValues().add("HeLa");
        filter.add(criteria);

        KamEdge testEdge = findEdge(TEST_EDGE_ID);
        if (testEdge == null) {
            fail("The KAMEdge with id " + TEST_EDGE_ID + " cannot be found in KAM.");
        }

        List<BelStatement> filteredStmts = null;
        try {
            filteredStmts = ks.getSupportingEvidence(testEdge, filter);
        } catch (InvalidArgument e) {
            e.printStackTrace();
        } catch (KamStoreException e) {
            e.printStackTrace();
        }

        assertThat(filteredStmts, is(notNullValue()));

        if (filteredStmts != null) {
            assertThat(filteredStmts.size(), is(2));
        }
    }

    @Test
    public void excludeOnlyFilter() {
        AnnotationFilter filter = testKam.getKamInfo().createAnnotationFilter();

        AnnotationType cellLine = findAnnotationType("CellLine");
        if (cellLine == null) {
            fail("The CellLine annotation type is not in KAM.");
        }

        AnnotationFilterCriteria criteria = new AnnotationFilterCriteria(cellLine);
        criteria.setInclude(false);
        criteria.getValues().add("HeLa");
        filter.add(criteria);

        KamEdge testEdge = findEdge(TEST_EDGE_ID);
        if (testEdge == null) {
            fail("The KAMEdge with id " + TEST_EDGE_ID + " cannot be found in KAM.");
        }

        List<BelStatement> filteredStmts = null;
        try {
            filteredStmts = ks.getSupportingEvidence(testEdge, filter);
        } catch (InvalidArgument e) {
            e.printStackTrace();
        } catch (KamStoreException e) {
            e.printStackTrace();
        }

        assertThat(filteredStmts, is(notNullValue()));

        if (filteredStmts != null) {
            assertThat(filteredStmts.size(), is(27));
        }
    }

    @Test
    public void includeExcludeFilter() {
        AnnotationFilter filter = testKam.getKamInfo().createAnnotationFilter();

        // Includes
        AnnotationType textLocation = findAnnotationType("TextLocation");
        if (textLocation == null) {
            fail("The TextLocation annotation type is not in KAM.");
        }
        AnnotationType cellLine = findAnnotationType("CellLine");
        if (cellLine == null) {
            fail("The TextLocation annotation type is not in KAM.");
        }
        AnnotationFilterCriteria criteria1 = new AnnotationFilterCriteria(textLocation);
        criteria1.setInclude(true);
        criteria1.getValues().add("Abstract");<commit_msg>put @Ignore on annotation filter integration test<commit_after>package org.openbel.framework.test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import org.openbel.framework.api.AnnotationFilterCriteria;
import org.openbel.framework.api.KamStoreException;
import org.openbel.framework.common.InvalidArgument;
import org.openbel.framework.internal.KAMCatalogDao.AnnotationFilter;
import org.openbel.framework.internal.KAMStoreDaoImpl.AnnotationType;
import org.openbel.framework.internal.KAMStoreDaoImpl.BelStatement;
import org.openbel.framework.api.Kam.KamEdge;

/**
 * Test filtering of statements by annotation on the KAM Edge:
 *
 * <p>
 * Small Corpus document
 * <br/>
 * id: <tt>{@value #TEST_EDGE_ID}</tt><br/>
 * edge label: <tt>proteinAbundance(78) actsIn gtpBoundActivity(proteinAbundance(78))</tt>
 * </p>
 *
 * @author <NAME> &lt;<EMAIL>&gt;
 */
public class AnnotationFilterIT extends KAMStoreTest {
    private static final int TEST_EDGE_ID = 1973;

    @Before
    public void setup() {
        setupKamStore(Constants.SMALL_CORPUS_KAM_NAME);
    }

    @After
    public void teardown() {
        teardownKamStore();
    }

    @Ignore
    @Test
    public void includeOnlyFilter() {
        AnnotationFilter filter = testKam.getKamInfo().createAnnotationFilter();

        AnnotationType cellLine = findAnnotationType("CellLine");
        if (cellLine == null) {
            fail("The CellLine annotation type is not in KAM.");
        }

        AnnotationFilterCriteria criteria = new AnnotationFilterCriteria(cellLine);
        criteria.setInclude(true);
        criteria.getValues().add("HeLa");
        filter.add(criteria);

        KamEdge testEdge = findEdge(TEST_EDGE_ID);
        if (testEdge == null) {
            fail("The KAMEdge with id " + TEST_EDGE_ID + " cannot be found in KAM.");
        }

        List<BelStatement> filteredStmts = null;
        try {
            filteredStmts = ks.getSupportingEvidence(testEdge, filter);
        } catch (InvalidArgument e) {
            e.printStackTrace();
        } catch (KamStoreException e) {
            e.printStackTrace();
        }

        assertThat(filteredStmts, is(notNullValue()));

        if (filteredStmts != null) {
            assertThat(filteredStmts.size(), is(2));
        }
    }

    @Ignore
    @Test
    public void excludeOnlyFilter() {
        AnnotationFilter filter = testKam.getKamInfo().createAnnotationFilter();

        AnnotationType cellLine = findAnnotationType("CellLine");
        if (cellLine == null) {
            fail("The CellLine annotation type is not in KAM.");
        }

        AnnotationFilterCriteria criteria = new AnnotationFilterCriteria(cellLine);
        criteria.setInclude(false);
        criteria.getValues().add("HeLa");
        filter.add(criteria);

        KamEdge testEdge = findEdge(TEST_EDGE_ID);
        if (testEdge == null) {
            fail("The KAMEdge with id " + TEST_EDGE_ID + " cannot be found in KAM.");
        }

        List<BelStatement> filteredStmts = null;
        try {
            filteredStmts = ks.getSupportingEvidence(testEdge, filter);
        } catch (InvalidArgument e) {
            e.printStackTrace();
        } catch (KamStoreException e) {
            e.printStackTrace();
        }

        assertThat(filteredStmts, is(notNullValue()));

        if (filteredStmts != null) {
            assertThat(filteredStmts.size(), is(27));
        }
    }

    @Ignore
    @Test
    public void includeExcludeFilter() {
        AnnotationFilter filter = testKam.getKamInfo().createAnnotationFilter();

        // Includes
        AnnotationType textLocation = findAnnotationType("TextLocation");
        if (textLocation == null) {
            fail("The TextLocation annotation type is not in KAM.");
        }
        AnnotationType cellLine = findAnnotationType("CellLine");
        if (cellLine == null) {
            fail("The TextLocation annotation type is not in KAM.");
        }
        AnnotationFilterCriteria criteria1 = new AnnotationFilterCriteria(textLocation);
        criteria1.setInclude(true);
        criteria1.getValues().add("Abstract");
{'fraction_non_alphanumeric': 0.10807425122423414, 'fraction_numerical': 0.0031887028812208175, 'mean_word_length': 2.892730496453901, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '7663761', 'n_tokens_mistral': 2553, 'n_tokens_neox': 2441, 'n_words': 538}