
import pytest
from querent.kg.ner_helperfunctions.filter_triples import TripleFilter


"""
    Asynchronous test function to validate the filtering and clustering of triples.

    This test initializes a TripleFilter with specified thresholds, filters the input triples,
    and then clusters the remaining triples. It asserts that the number of triples filtered
    and clustered matches the expected counts.

    Parameters:
    - triples (list of tuples): The input triples to be filtered and clustered.
    - score_threshold (float): The threshold for filtering based on entity scores.
    - attention_score_threshold (float): The threshold for filtering based on attention scores.
    - similarity_threshold (float): The threshold for filtering based on embedding similarity.
    - min_cluster_size (int): The minimum size of clusters to be formed.
    - min_samples (int): The number of samples in a neighborhood for a point to be considered a core point.
    - expected_filtered_count (int): The expected number of triples to be filtered out.
    - expected_clustered_count (int): The expected number of triples to be clustered.

    Assertions:
    - The number of triples filtered out matches the expected_filtered_count.
    - The number of triples after filtering matches the original count minus expected_filtered_count.
    - The number of triples clustered out matches the expected_clustered_count.
    - The number of triples after clustering matches the original count minus expected_clustered_count.
"""

# Define the test data and expected results
@pytest.mark.parametrize("triples, score_threshold, attention_score_threshold, similarity_threshold, min_cluster_size, min_samples, expected_filtered_count, expected_clustered_count", 
                        [([('eocene', '{"context": "In this study, we present evidence of a Paleocene\\u2013Eocene Thermal Maximum (PETM) record within a 543-m-thick (1780 ft) deep-marine section in the Gulf of Mexico (GoM) using organic carbon stable isotopes and biostratigraphic constraints. We suggest that climate and tectonic perturbations in the upstream North American catchments can induce a substantial response in the downstream sectors of the Gulf Coastal Plain and ultimately in the GoM.", "entity1_score": 1.0, "entity2_score": 0.69, "entity1_label": "B-GeoTime, B-GeoMeth", "entity2_label": "B-GeoMeth", "entity1_nn_chunk": "a Paleocene\\u2013Eocene Thermal Maximum (PETM) record", "entity2_nn_chunk": "a 543-m-thick (1780 ft) deep-marine section", "file_path": "dummy_1_file.txt", "entity1_attnscore": 0.2, "entity2_attnscore": 0.09, "pair_attnscore": 0.12, "entity1_embedding": [2.7497622966766357, -0.5454338788986206, 6.291350364685059, 8.717966079711914, 3.0895700454711914, 2.3901493549346924, 2.462153673171997, 2.4761993885040283, 3.185384511947632, 12.142127990722656], "entity2_embedding": [3.7323296070098877, -1.4545331001281738, 6.134968280792236, 8.18924331665039, 2.7829885482788086, 4.156617164611816, 1.9409900903701782, 2.868553876876831, 4.041325569152832, 13.211334228515625], "sentence_embedding": [8.273744583129883, 2.051804780960083, 9.59654426574707, -2.3267648220062256, 9.436607360839844, 10.587993621826172, -7.340267181396484, 4.733699321746826, 5.80666971206665, 5.723113536834717]}', 'ft'), 
           ('eocene', '{"context": "In this study, we present evidence of a Paleocene\\u2013Eocene Thermal Maximum (PETM) record within a 543-m-thick (1780 ft) deep-marine section in the Gulf of Mexico (GoM) using organic carbon stable isotopes and biostratigraphic constraints. We suggest that climate and tectonic perturbations in the upstream North American catchments can induce a substantial response in the downstream sectors of the Gulf Coastal Plain and ultimately in the GoM.", "entity1_score": 1.0, "entity2_score": 0.92, "entity1_label": "B-GeoTime, B-GeoMeth", "entity2_label": "B-GeoLoc", "entity1_nn_chunk": "a Paleocene\\u2013Eocene Thermal Maximum (PETM) record", "entity2_nn_chunk": "Mexico", "file_path": "dummy_1_file.txt", "entity1_attnscore": 0.2, "entity2_attnscore": 0.09, "pair_attnscore": 0.13, "entity1_embedding": [2.6488053798675537, -0.6798055768013, 6.543962478637695, 8.325488090515137, 3.091782331466675, 2.573601722717285, 2.505544900894165, 2.2582333087921143, 3.1716434955596924, 12.096002578735352], "entity2_embedding": [3.2900171279907227, -3.1185624599456787, 6.074228286743164, 8.012141227722168, 2.4355814456939697, 3.655385732650757, 2.7318809032440186, 2.2702815532684326, 3.1232528686523438, 12.755410194396973], "sentence_embedding": [8.274189949035645, 2.051741600036621, 9.596600532531738, -2.326831579208374, 9.588064193725586, 10.738533973693848, -7.178147792816162, 4.895790100097656, 5.51309061050415, 5.5418500900268555]}', 'mexico'), 
           ('eocene', '{"context": "In this study, we present evidence of a Paleocene\\u2013Eocene Thermal Maximum (PETM) record within a 543-m-thick (1780 ft) deep-marine section in the Gulf of Mexico (GoM) using organic carbon stable isotopes and biostratigraphic constraints. We suggest that climate and tectonic perturbations in the upstream North American catchments can induce a substantial response in the downstream sectors of the Gulf Coastal Plain and ultimately in the GoM.", "entity1_score": 1.0, "entity2_score": 0.98, "entity1_label": "B-GeoTime, B-GeoMeth", "entity2_label": "B-GeoMeth, B-GeoPetro", "entity1_nn_chunk": "a Paleocene\\u2013Eocene Thermal Maximum (PETM) record", "entity2_nn_chunk": "organic carbon stable isotopes", "file_path": "dummy_1_file.txt", "entity1_attnscore": 0.2, "entity2_attnscore": 0.21, "pair_attnscore": 0.21, "entity1_embedding": [2.792264461517334, -0.5597057938575745, 6.471883773803711, 8.395708084106445, 3.065075159072876, 2.7189583778381348, 2.3715662956237793, 2.3874168395996094, 3.2599542140960693, 12.358487129211426], "entity2_embedding": [3.6428165435791016, -0.1321650743484497, 5.9235968589782715, 8.318928718566895, 2.0116961002349854, 2.7097012996673584, 2.3251116275787354, 2.9655239582061768, 2.381112813949585, 11.753918647766113], "sentence_embedding": [8.273637771606445, 2.0518276691436768, 9.596525192260742, -2.3267481327056885, 9.410528182983398, 10.562018394470215, -7.365957736968994, 4.708027362823486, 5.797874927520752, 5.788640975952148]}', 'organic'), 
           ('ft', '{"context": "In this study, we present evidence of a Paleocene\\u2013Eocene Thermal Maximum (PETM) record within a 543-m-thick (1780 ft) deep-marine section in the Gulf of Mexico (GoM) using organic carbon stable isotopes and biostratigraphic constraints. We suggest that climate and tectonic perturbations in the upstream North American catchments can induce a substantial response in the downstream sectors of the Gulf Coastal Plain and ultimately in the GoM.", "entity1_score": 0.69, "entity2_score": 0.92, "entity1_label": "B-GeoMeth", "entity2_label": "B-GeoLoc", "entity1_nn_chunk": "a 543-m-thick (1780 ft) deep-marine section", "entity2_nn_chunk": "Mexico", "file_path": "dummy_1_file.txt", "entity1_attnscore": 0.09, "entity2_attnscore": 0.09, "pair_attnscore": 0.09, "entity1_embedding": [3.9145333766937256, -1.3819427490234375, 6.232261657714844, 7.93341064453125, 3.304962635040283, 3.6077494621276855, 1.7642797231674194, 2.5056090354919434, 4.156083106994629, 12.344873428344727], "entity2_embedding": [3.252547025680542, -2.6739959716796875, 6.196337699890137, 7.94928503036499, 2.37715482711792, 3.465878486633301, 2.636854887008667, 2.277503728866577, 2.9351625442504883, 13.037396430969238], "sentence_embedding": [8.273326873779297, 2.0518717765808105, 9.596479415893555, -2.326699733734131, 9.342904090881348, 10.494515419006348, -7.430538177490234, 4.64348030090332, 5.878793239593506, 5.812100410461426]}', 'mexico'), 
           ('ft', '{"context": "In this study, we present evidence of a Paleocene\\u2013Eocene Thermal Maximum (PETM) record within a 543-m-thick (1780 ft) deep-marine section in the Gulf of Mexico (GoM) using organic carbon stable isotopes and biostratigraphic constraints. We suggest that climate and tectonic perturbations in the upstream North American catchments can induce a substantial response in the downstream sectors of the Gulf Coastal Plain and ultimately in the GoM.", "entity1_score": 0.69, "entity2_score": 0.98, "entity1_label": "B-GeoMeth", "entity2_label": "B-GeoMeth, B-GeoPetro", "entity1_nn_chunk": "a 543-m-thick (1780 ft) deep-marine section", "entity2_nn_chunk": "organic carbon stable isotopes", "file_path": "dummy_1_file.txt", "entity1_attnscore": 0.09, "entity2_attnscore": 0.21, "pair_attnscore": 0.12, "entity1_embedding": [3.72121262550354, -1.2197364568710327, 6.335819244384766, 7.918046474456787, 3.3196980953216553, 4.441747665405273, 1.680811882019043, 2.783958673477173, 3.540374994277954, 12.884989738464355], "entity2_embedding": [3.5021800994873047, -0.06335429102182388, 5.944340229034424, 8.448829650878906, 1.9487491846084595, 2.593893527984619, 2.2817087173461914, 3.0285210609436035, 2.276712417602539, 11.722785949707031], "sentence_embedding": [8.273797035217285, 2.0517985820770264, 9.596549987792969, -2.3267695903778076, 9.452091217041016, 10.603425979614258, -7.32454776763916, 4.7494096755981445, 5.788027763366699, 5.748314380645752]}', 'organic'),
           ('mexico', '{"context": "In this study, we present evidence of a Paleocene\\u2013Eocene Thermal Maximum (PETM) record within a 543-m-thick (1780 ft) deep-marine section in the Gulf of Mexico (GoM) using organic carbon stable isotopes and biostratigraphic constraints. We suggest that climate and tectonic perturbations in the upstream North American catchments can induce a substantial response in the downstream sectors of the Gulf Coastal Plain and ultimately in the GoM.", "entity1_score": 0.92, "entity2_score": 0.98, "entity1_label": "B-GeoLoc", "entity2_label": "B-GeoMeth, B-GeoPetro", "entity1_nn_chunk": "Mexico", "entity2_nn_chunk": "organic carbon stable isotopes", "file_path": "dummy_1_file.txt", "entity1_attnscore": 0.09, "entity2_attnscore": 0.21, "pair_attnscore": 0.13, "entity1_embedding": [3.144767999649048, -2.7147321701049805, 6.127165794372559, 8.295948028564453, 2.8409361839294434, 3.421802282333374, 2.720162868499756, 1.9653069972991943, 3.038386106491089, 12.980123519897461], "entity2_embedding": [3.5817856788635254, -0.024259988218545914, 5.900996208190918, 8.518841743469238, 2.084223985671997, 2.620420455932617, 2.407585859298706, 3.089611768722534, 2.2546801567077637, 11.82196044921875], "sentence_embedding": [8.273309707641602, 2.051867723464966, 9.596478462219238, -2.3266983032226562, 9.337979316711426, 10.48964786529541, -7.436363697052002, 4.637650012969971, 5.869350433349609, 5.816451072692871]}', 'organic'), 
           ('tectonic', '{"context": "In this study, we present evidence of a Paleocene\\u2013Eocene Thermal Maximum (PETM) record within a 543-m-thick (1780 ft) deep-marine section in the Gulf of Mexico (GoM) using organic carbon stable isotopes and biostratigraphic constraints. We suggest that climate and tectonic perturbations in the upstream North American catchments can induce a substantial response in the downstream sectors of the Gulf Coastal Plain and ultimately in the GoM. This relationship is illustrated in the deep-water basin by (1) a high accom- modation and deposition of a shale interval when coarse-grained terrigenous material was trapped upstream at the onset of the PETM, and (2) a considerable increase in sedi- ment supply during the PETM, which is archived as a particularly thick sedimentary section in the deep-sea fans of the GoM basin.", "entity1_score": 1.0, "entity2_score": 1.0, "entity1_label": "B-GeoPetro", "entity2_label": "B-GeoMeth", "entity1_nn_chunk": "tectonic perturbations", "entity2_nn_chunk": "the upstream North American catchments", "file_path": "dummy_1_file.txt", "entity1_attnscore": 0.25, "entity2_attnscore": 0.11, "pair_attnscore": 0.15, "entity1_embedding": [3.6411795616149902, -1.5020869970321655, 5.696325778961182, 8.604700088500977, 1.5151718854904175, 3.677309274673462, 2.884289264678955, 2.873039484024048, 1.5940958261489868, 11.50014591217041], "entity2_embedding": [3.9356887340545654, -0.4274052679538727, 6.138661861419678, 8.16846752166748, 2.308915376663208, 4.314570426940918, 1.8623437881469727, 3.321876049041748, 3.1112611293792725, 12.501526832580566], "sentence_embedding": [8.273104667663574, 2.0518875122070312, 9.596617698669434, -2.3267197608947754, 7.928299903869629, 9.09572696685791, -9.138922691345215, 2.935373067855835, 4.520363807678223, 4.727715015411377]}', 'upstream'), 
           ('tectonic', '{"context": "In this study, we present evidence of a Paleocene\\u2013Eocene Thermal Maximum (PETM) record within a 543-m-thick (1780 ft) deep-marine section in the Gulf of Mexico (GoM) using organic carbon stable isotopes and biostratigraphic constraints. We suggest that climate and tectonic perturbations in the upstream North American catchments can induce a substantial response in the downstream sectors of the Gulf Coastal Plain and ultimately in the GoM. This relationship is illustrated in the deep-water basin by (1) a high accom- modation and deposition of a shale interval when coarse-grained terrigenous material was trapped upstream at the onset of the PETM, and (2) a considerable increase in sedi- ment supply during the PETM, which is archived as a particularly thick sedimentary section in the deep-sea fans of the GoM basin.", "entity1_score": 1.0, "entity2_score": 1.0, "entity1_label": "B-GeoPetro", "entity2_label": "B-GeoPetro", "entity1_nn_chunk": "tectonic perturbations", "entity2_nn_chunk": "the downstream sectors", "file_path": "dummy_1_file.txt", "entity1_attnscore": 0.25, "entity2_attnscore": 0.49, "pair_attnscore": 0.33, "entity1_embedding": [3.85038685798645, -1.3444548845291138, 5.504477024078369, 8.894646644592285, 1.6295241117477417, 3.37282395362854, 2.5772287845611572, 3.101915121078491, 1.5097862482070923, 11.506526947021484], "entity2_embedding": [3.9193172454833984, -1.6295044422149658, 5.632161617279053, 7.854856967926025, 1.1065350770950317, 2.7394042015075684, 2.5630269050598145, 2.9742021560668945, 1.9695501327514648, 11.684067726135254], "sentence_embedding": [8.274432182312012, 2.051668167114258, 9.596901893615723, -2.3269529342651367, 7.91616678237915, 9.085306167602539, -9.196913719177246, 2.8773529529571533, 4.365344524383545, 4.512395858764648]}', 'downstream'), 
           ('tectonic', '{"context": "In this study, we present evidence of a Paleocene\\u2013Eocene Thermal Maximum (PETM) record within a 543-m-thick (1780 ft) deep-marine section in the Gulf of Mexico (GoM) using organic carbon stable isotopes and biostratigraphic constraints. We suggest that climate and tectonic perturbations in the upstream North American catchments can induce a substantial response in the downstream sectors of the Gulf Coastal Plain and ultimately in the GoM. This relationship is illustrated in the deep-water basin by (1) a high accom- modation and deposition of a shale interval when coarse-grained terrigenous material was trapped upstream at the onset of the PETM, and (2) a considerable increase in sedi- ment supply during the PETM, which is archived as a particularly thick sedimentary section in the deep-sea fans of the GoM basin.", "entity1_score": 1.0, "entity2_score": 0.98, "entity1_label": "B-GeoPetro", "entity2_label": "B-GeoPetro", "entity1_nn_chunk": "tectonic perturbations", "entity2_nn_chunk": "the Gulf Coastal Plain", "file_path": "dummy_1_file.txt", "entity1_attnscore": 0.25, "entity2_attnscore": 0.24, "pair_attnscore": 0.24, "entity1_embedding": [3.5848329067230225, -1.487343668937683, 5.6952009201049805, 8.473453521728516, 1.5355619192123413, 3.6111767292022705, 2.654287099838257, 3.0325963497161865, 1.4424744844436646, 11.632696151733398], "entity2_embedding": [4.40934944152832, -2.6414687633514404, 5.719301700592041, 8.166884422302246, 1.9718804359436035, 3.195392608642578, 2.2786951065063477, 2.728088140487671, 3.600144386291504, 12.685139656066895], "sentence_embedding": [8.171407699584961, 2.0686159133911133, 9.576199531555176, -2.308645725250244, 8.752703666687012, 9.852017402648926, -7.976686954498291, 4.097899436950684, 2.8626537322998047, 3.544607162475586]}', 'coastal'), 
           ('upstream', '{"context": "In this study, we present evidence of a Paleocene\\u2013Eocene Thermal Maximum (PETM) record within a 543-m-thick (1780 ft) deep-marine section in the Gulf of Mexico (GoM) using organic carbon stable isotopes and biostratigraphic constraints. We suggest that climate and tectonic perturbations in the upstream North American catchments can induce a substantial response in the downstream sectors of the Gulf Coastal Plain and ultimately in the GoM. This relationship is illustrated in the deep-water basin by (1) a high accom- modation and deposition of a shale interval when coarse-grained terrigenous material was trapped upstream at the onset of the PETM, and (2) a considerable increase in sedi- ment supply during the PETM, which is archived as a particularly thick sedimentary section in the deep-sea fans of the GoM basin.", "entity1_score": 1.0, "entity2_score": 1.0, "entity1_label": "B-GeoMeth", "entity2_label": "B-GeoPetro", "entity1_nn_chunk": "the upstream North American catchments", "entity2_nn_chunk": "the downstream sectors", "file_path": "dummy_1_file.txt", "entity1_attnscore": 0.11, "entity2_attnscore": 0.49, "pair_attnscore": 0.18, "entity1_embedding": [3.781593084335327, -0.8344725370407104, 6.194002151489258, 8.271034240722656, 2.546635389328003, 4.471875190734863, 1.8119113445281982, 3.2294750213623047, 2.757159471511841, 12.193735122680664], "entity2_embedding": [4.007772922515869, -1.539210557937622, 5.661635398864746, 7.687388896942139, 1.4495539665222168, 2.722914934158325, 2.4864203929901123, 2.8783230781555176, 2.188131809234619, 11.470794677734375], "sentence_embedding": [8.274091720581055, 2.0517280101776123, 9.596802711486816, -2.3268887996673584, 7.976433277130127, 9.145756721496582, -9.147445678710938, 2.926783561706543, 4.40964412689209, 4.408041000366211]}', 'downstream'), 
           ('upstream', '{"context": "In this study, we present evidence of a Paleocene\\u2013Eocene Thermal Maximum (PETM) record within a 543-m-thick (1780 ft) deep-marine section in the Gulf of Mexico (GoM) using organic carbon stable isotopes and biostratigraphic constraints. We suggest that climate and tectonic perturbations in the upstream North American catchments can induce a substantial response in the downstream sectors of the Gulf Coastal Plain and ultimately in the GoM. This relationship is illustrated in the deep-water basin by (1) a high accom- modation and deposition of a shale interval when coarse-grained terrigenous material was trapped upstream at the onset of the PETM, and (2) a considerable increase in sedi- ment supply during the PETM, which is archived as a particularly thick sedimentary section in the deep-sea fans of the GoM basin.", "entity1_score": 1.0, "entity2_score": 0.98, "entity1_label": "B-GeoMeth", "entity2_label": "B-GeoPetro", "entity1_nn_chunk": "the upstream North American catchments", "entity2_nn_chunk": "the Gulf Coastal Plain", "file_path": "dummy_1_file.txt", "entity1_attnscore": 0.11, "entity2_attnscore": 0.24, "pair_attnscore": 0.15, "entity1_embedding": [3.7742319107055664, -0.7761141657829285, 6.207308769226074, 8.10714340209961, 2.6537845134735107, 4.6391167640686035, 1.713283658027649, 3.2407264709472656, 3.028916597366333, 12.314061164855957], "entity2_embedding": [4.119009494781494, -2.451376438140869, 5.714200496673584, 8.16775131225586, 1.5697892904281616, 3.016974449157715, 2.3051607608795166, 2.6763205528259277, 4.043854236602783, 12.48615837097168], "sentence_embedding": [8.274133682250977, 2.0517232418060303, 9.596816062927246, -2.326892375946045, 7.954324722290039, 9.124204635620117, -9.18288803100586, 2.8913755416870117, 4.316779613494873, 4.332244873046875]}', 'coastal'), 
           ('downstream', '{"context": "In this study, we present evidence of a Paleocene\\u2013Eocene Thermal Maximum (PETM) record within a 543-m-thick (1780 ft) deep-marine section in the Gulf of Mexico (GoM) using organic carbon stable isotopes and biostratigraphic constraints. We suggest that climate and tectonic perturbations in the upstream North American catchments can induce a substantial response in the downstream sectors of the Gulf Coastal Plain and ultimately in the GoM. This relationship is illustrated in the deep-water basin by (1) a high accom- modation and deposition of a shale interval when coarse-grained terrigenous material was trapped upstream at the onset of the PETM, and (2) a considerable increase in sedi- ment supply during the PETM, which is archived as a particularly thick sedimentary section in the deep-sea fans of the GoM basin.", "entity1_score": 1.0, "entity2_score": 0.98, "entity1_label": "B-GeoPetro", "entity2_label": "B-GeoPetro", "entity1_nn_chunk": "the downstream sectors", "entity2_nn_chunk": "the Gulf Coastal Plain", "file_path": "dummy_1_file.txt", "entity1_attnscore": 0.49, "entity2_attnscore": 0.24, "pair_attnscore": 0.32, "entity1_embedding": [3.9212284088134766, -1.6629095077514648, 5.521124362945557, 7.751332759857178, 1.503126621246338, 2.7465665340423584, 2.5462348461151123, 2.9435184001922607, 1.9544049501419067, 11.384193420410156], "entity2_embedding": [3.904635190963745, -2.3259449005126953, 5.728708267211914, 8.567526817321777, 1.8445405960083008, 3.1008949279785156, 2.3495540618896484, 2.6896140575408936, 4.384907245635986, 12.416000366210938], "sentence_embedding": [8.274145126342773, 2.0517215728759766, 9.59683609008789, -2.3269004821777344, 7.935454845428467, 9.104917526245117, -9.188153266906738, 2.8860979080200195, 4.3856353759765625, 4.518765926361084]}', 'coastal'), 
           ('basin', '{"context": "We suggest that climate and tectonic perturbations in the upstream North American catchments can induce a substantial response in the downstream sectors of the Gulf Coastal Plain and ultimately in the GoM. This relationship is illustrated in the deep-water basin by (1) a high accom- modation and deposition of a shale interval when coarse-grained terrigenous material was trapped upstream at the onset of the PETM, and (2) a considerable increase in sedi- ment supply during the PETM, which is archived as a particularly thick sedimentary section in the deep-sea fans of the GoM basin. Despite other thick PETM sections being observed elsewhere in the world, the one described in this study links with a continental- scale paleo-drainage, which makes it of particular interest for paleoclimate and source- to-sink reconstructions.", "entity1_score": 1.0, "entity2_score": 1.0, "entity1_label": "B-GeoPetro", "entity2_label": "B-GeoPetro", "entity1_nn_chunk": "the GoM basin", "entity2_nn_chunk": "deposition", "file_path": "dummy_1_file.txt", "entity1_attnscore": 0.26, "entity2_attnscore": 0.26, "pair_attnscore": 0.26, "entity1_embedding": [3.779275417327881, -2.450312376022339, 5.564785957336426, 9.048267364501953, 1.158644199371338, 2.5670621395111084, 2.868556499481201, 2.8476035594940186, 2.626718044281006, 11.972245216369629], "entity2_embedding": [3.8690717220306396, -1.558268427848816, 5.745287895202637, 8.37027359008789, 1.8900668621063232, 2.226731777191162, 2.4036779403686523, 2.7072699069976807, 1.3761074542999268, 11.92121410369873], "sentence_embedding": [8.26048469543457, 2.0539541244506836, 9.59400463104248, -2.3245110511779785, 8.029595375061035, 9.17389965057373, -8.415410041809082, 3.659198522567749, 3.3177754878997803, 3.4890079498291016]}', 'deposition'), 
           ('basin', '{"context": "We suggest that climate and tectonic perturbations in the upstream North American catchments can induce a substantial response in the downstream sectors of the Gulf Coastal Plain and ultimately in the GoM. This relationship is illustrated in the deep-water basin by (1) a high accom- modation and deposition of a shale interval when coarse-grained terrigenous material was trapped upstream at the onset of the PETM, and (2) a considerable increase in sedi- ment supply during the PETM, which is archived as a particularly thick sedimentary section in the deep-sea fans of the GoM basin. Despite other thick PETM sections being observed elsewhere in the world, the one described in this study links with a continental- scale paleo-drainage, which makes it of particular interest for paleoclimate and source- to-sink reconstructions.", "entity1_score": 1.0, "entity2_score": 1.0, "entity1_label": "B-GeoPetro", "entity2_label": "B-GeoPetro", "entity1_nn_chunk": "the GoM basin", "entity2_nn_chunk": "a shale interval", "file_path": "dummy_1_file.txt", "entity1_attnscore": 0.26, "entity2_attnscore": 0.1, "pair_attnscore": 0.14, "entity1_embedding": [4.119443416595459, -2.4170005321502686, 5.506854057312012, 8.978416442871094, 1.1511424779891968, 2.5173678398132324, 2.7195496559143066, 2.852993965148926, 2.2741880416870117, 12.252689361572266], "entity2_embedding": [3.9250998497009277, -0.9356150031089783, 5.388732433319092, 9.552205085754395, 1.5140143632888794, 2.5319619178771973, 2.372610330581665, 3.2776687145233154, 1.8205068111419678, 12.066429138183594], "sentence_embedding": [8.265246391296387, 2.0531725883483887, 9.594969749450684, -2.3253417015075684, 8.152375221252441, 9.298916816711426, -8.365521430969238, 3.7090201377868652, 3.5349483489990234, 3.0754904747009277]}', 'shale'), 
           ('basin', '{"context": "We suggest that climate and tectonic perturbations in the upstream North American catchments can induce a substantial response in the downstream sectors of the Gulf Coastal Plain and ultimately in the GoM. This relationship is illustrated in the deep-water basin by (1) a high accom- modation and deposition of a shale interval when coarse-grained terrigenous material was trapped upstream at the onset of the PETM, and (2) a considerable increase in sedi- ment supply during the PETM, which is archived as a particularly thick sedimentary section in the deep-sea fans of the GoM basin. Despite other thick PETM sections being observed elsewhere in the world, the one described in this study links with a continental- scale paleo-drainage, which makes it of particular interest for paleoclimate and source- to-sink reconstructions.", "entity1_score": 1.0, "entity2_score": 1.0, "entity1_label": "B-GeoPetro", "entity2_label": "B-GeoPetro", "entity1_nn_chunk": "the GoM basin", "entity2_nn_chunk": "coarse-grained terrigenous material", "file_path": "dummy_1_file.txt", "entity1_attnscore": 0.26, "entity2_attnscore": 0.05, "pair_attnscore": 0.09, "entity1_embedding": [4.108553409576416, -2.4838831424713135, 5.380271911621094, 9.477745056152344, 1.5617849826812744, 2.5357635021209717, 2.673309564590454, 2.7784769535064697, 2.1955718994140625, 12.205521583557129], "entity2_embedding": [4.0050835609436035, -1.1028891801834106, 5.440834045410156, 9.748600959777832, 1.7639741897583008, 2.5701112747192383, 2.4116194248199463, 2.9646735191345215, 2.2542827129364014, 11.504647254943848], "sentence_embedding": [8.258162498474121, 2.0543270111083984, 9.593584060668945, -2.324106454849243, 7.6216044425964355, 8.752443313598633, -8.413619995117188, 3.6613075733184814, 3.641577959060669, 3.4947078227996826]}', 'coarse'), 
           ('basin', '{"context": "We suggest that climate and tectonic perturbations in the upstream North American catchments can induce a substantial response in the downstream sectors of the Gulf Coastal Plain and ultimately in the GoM. This relationship is illustrated in the deep-water basin by (1) a high accom- modation and deposition of a shale interval when coarse-grained terrigenous material was trapped upstream at the onset of the PETM, and (2) a considerable increase in sedi- ment supply during the PETM, which is archived as a particularly thick sedimentary section in the deep-sea fans of the GoM basin. Despite other thick PETM sections being observed elsewhere in the world, the one described in this study links with a continental- scale paleo-drainage, which makes it of particular interest for paleoclimate and source- to-sink reconstructions.", "entity1_score": 1.0, "entity2_score": 1.0, "entity1_label": "B-GeoPetro", "entity2_label": "B-GeoMeth", "entity1_nn_chunk": "the GoM basin", "entity2_nn_chunk": "upstream", "file_path": "dummy_1_file.txt", "entity1_attnscore": 0.26, "entity2_attnscore": 0.09, "pair_attnscore": 0.13, "entity1_embedding": [3.736577033996582, -2.4790451526641846, 5.554500102996826, 9.023608207702637, 1.1513177156448364, 2.42797589302063, 2.8700180053710938, 2.8867266178131104, 2.2713053226470947, 12.193184852600098], "entity2_embedding": [3.824883222579956, -0.5760443806648254, 6.2958478927612305, 8.043895721435547, 2.6064090728759766, 4.462185382843018, 1.701485276222229, 3.265139102935791, 2.85941743850708, 12.199705123901367], "sentence_embedding": [8.258600234985352, 2.0542502403259277, 9.593637466430664, -2.3241846561431885, 7.877345085144043, 9.01498031616211, -8.370376586914062, 3.704374074935913, 3.5215251445770264, 3.322709083557129]}', 'upstream'), 
           ('deposition', '{"context": "We suggest that climate and tectonic perturbations in the upstream North American catchments can induce a substantial response in the downstream sectors of the Gulf Coastal Plain and ultimately in the GoM. This relationship is illustrated in the deep-water basin by (1) a high accom- modation and deposition of a shale interval when coarse-grained terrigenous material was trapped upstream at the onset of the PETM, and (2) a considerable increase in sedi- ment supply during the PETM, which is archived as a particularly thick sedimentary section in the deep-sea fans of the GoM basin. Despite other thick PETM sections being observed elsewhere in the world, the one described in this study links with a continental- scale paleo-drainage, which makes it of particular interest for paleoclimate and source- to-sink reconstructions.", "entity1_score": 1.0, "entity2_score": 1.0, "entity1_label": "B-GeoPetro", "entity2_label": "B-GeoPetro", "entity1_nn_chunk": "deposition", "entity2_nn_chunk": "a shale interval", "file_path": "dummy_1_file.txt", "entity1_attnscore": 0.26, "entity2_attnscore": 0.1, "pair_attnscore": 0.14, "entity1_embedding": [4.037097454071045, -1.5482368469238281, 5.687910079956055, 8.639769554138184, 2.0061299800872803, 2.580061912536621, 2.3091812133789062, 2.835251808166504, 0.9321686029434204, 11.964442253112793], "entity2_embedding": [3.823697328567505, -0.8554319143295288, 5.418757915496826, 9.303988456726074, 1.4667565822601318, 2.4567506313323975, 2.3202929496765137, 3.2809736728668213, 1.8063433170318604, 12.352104187011719], "sentence_embedding": [8.265887260437012, 2.0530619621276855, 9.595108985900879, -2.325455904006958, 8.23084545135498, 9.379379272460938, -8.350030899047852, 3.7244553565979004, 3.357015609741211, 3.0107994079589844]}', 'shale'), 
           ('deposition', '{"context": "We suggest that climate and tectonic perturbations in the upstream North American catchments can induce a substantial response in the downstream sectors of the Gulf Coastal Plain and ultimately in the GoM. This relationship is illustrated in the deep-water basin by (1) a high accom- modation and deposition of a shale interval when coarse-grained terrigenous material was trapped upstream at the onset of the PETM, and (2) a considerable increase in sedi- ment supply during the PETM, which is archived as a particularly thick sedimentary section in the deep-sea fans of the GoM basin. Despite other thick PETM sections being observed elsewhere in the world, the one described in this study links with a continental- scale paleo-drainage, which makes it of particular interest for paleoclimate and source- to-sink reconstructions.", "entity1_score": 1.0, "entity2_score": 1.0, "entity1_label": "B-GeoPetro", "entity2_label": "B-GeoPetro", "entity1_nn_chunk": "deposition", "entity2_nn_chunk": "coarse-grained terrigenous material", "file_path": "dummy_1_file.txt", "entity1_attnscore": 0.26, "entity2_attnscore": 0.05, "pair_attnscore": 0.09, "entity1_embedding": [4.022927761077881, -1.2513703107833862, 5.67182731628418, 8.537543296813965, 1.5244730710983276, 2.4617042541503906, 2.345921516418457, 3.041199207305908, 1.4364830255508423, 11.754050254821777], "entity2_embedding": [4.1893534660339355, -0.9747512936592102, 5.430134296417236, 9.750176429748535, 1.9102195501327515, 2.4549989700317383, 2.4048633575439453, 2.9038901329040527, 2.405259132385254, 11.941838264465332], "sentence_embedding": [8.260772705078125, 2.053903579711914, 9.594109535217285, -2.324568748474121, 7.807742595672607, 8.947274208068848, -8.485549926757812, 3.589221954345703, 3.6893534660339355, 3.214524030685425]}', 'coarse'), 
           ('deposition', '{"context": "We suggest that climate and tectonic perturbations in the upstream North American catchments can induce a substantial response in the downstream sectors of the Gulf Coastal Plain and ultimately in the GoM. This relationship is illustrated in the deep-water basin by (1) a high accom- modation and deposition of a shale interval when coarse-grained terrigenous material was trapped upstream at the onset of the PETM, and (2) a considerable increase in sedi- ment supply during the PETM, which is archived as a particularly thick sedimentary section in the deep-sea fans of the GoM basin. Despite other thick PETM sections being observed elsewhere in the world, the one described in this study links with a continental- scale paleo-drainage, which makes it of particular interest for paleoclimate and source- to-sink reconstructions.", "entity1_score": 1.0, "entity2_score": 1.0, "entity1_label": "B-GeoPetro", "entity2_label": "B-GeoMeth", "entity1_nn_chunk": "deposition", "entity2_nn_chunk": "upstream", "file_path": "dummy_1_file.txt", "entity1_attnscore": 0.26, "entity2_attnscore": 0.09, "pair_attnscore": 0.13, "entity1_embedding": [4.127425193786621, -1.5212538242340088, 5.6802496910095215, 8.361967086791992, 1.9768118858337402, 2.3448410034179688, 2.362427234649658, 2.735774278640747, 1.5828312635421753, 11.465723037719727], "entity2_embedding": [4.109014511108398, -0.7797077894210815, 6.112752437591553, 8.394779205322266, 2.451874017715454, 4.320161819458008, 1.620858907699585, 3.317976236343384, 2.830693483352661, 12.318888664245605], "sentence_embedding": [8.26502513885498, 2.053211212158203, 9.594893455505371, -2.3252992630004883, 8.202630043029785, 9.348957061767578, -8.314787864685059, 3.7597386837005615, 3.485481023788452, 3.1397032737731934]}', 'upstream'), 
           ('shale', '{"context": "We suggest that climate and tectonic perturbations in the upstream North American catchments can induce a substantial response in the downstream sectors of the Gulf Coastal Plain and ultimately in the GoM. This relationship is illustrated in the deep-water basin by (1) a high accom- modation and deposition of a shale interval when coarse-grained terrigenous material was trapped upstream at the onset of the PETM, and (2) a considerable increase in sedi- ment supply during the PETM, which is archived as a particularly thick sedimentary section in the deep-sea fans of the GoM basin. Despite other thick PETM sections being observed elsewhere in the world, the one described in this study links with a continental- scale paleo-drainage, which makes it of particular interest for paleoclimate and source- to-sink reconstructions.", "entity1_score": 1.0, "entity2_score": 1.0, "entity1_label": "B-GeoPetro", "entity2_label": "B-GeoPetro", "entity1_nn_chunk": "a shale interval", "entity2_nn_chunk": "coarse-grained terrigenous material", "file_path": "dummy_1_file.txt", "entity1_attnscore": 0.1, "entity2_attnscore": 0.05, "pair_attnscore": 0.07, "entity1_embedding": [3.8545055389404297, -1.1383901834487915, 5.378453731536865, 9.810062408447266, 1.592409610748291, 2.8200225830078125, 2.433525562286377, 3.1255710124969482, 1.8716100454330444, 11.913195610046387], "entity2_embedding": [4.333093643188477, -0.8805223703384399, 5.475193977355957, 9.671239852905273, 2.063199520111084, 2.3700921535491943, 2.3002822399139404, 2.8283228874206543, 2.4080417156219482, 11.918879508972168], "sentence_embedding": [8.267016410827637, 2.052884101867676, 9.595311164855957, -2.325650453567505, 8.268800735473633, 9.418998718261719, -8.360254287719727, 3.714193344116211, 3.7852654457092285, 2.7610220909118652]}', 'coarse'), 
           ('shale', '{"context": "We suggest that climate and tectonic perturbations in the upstream North American catchments can induce a substantial response in the downstream sectors of the Gulf Coastal Plain and ultimately in the GoM. This relationship is illustrated in the deep-water basin by (1) a high accom- modation and deposition of a shale interval when coarse-grained terrigenous material was trapped upstream at the onset of the PETM, and (2) a considerable increase in sedi- ment supply during the PETM, which is archived as a particularly thick sedimentary section in the deep-sea fans of the GoM basin. Despite other thick PETM sections being observed elsewhere in the world, the one described in this study links with a continental- scale paleo-drainage, which makes it of particular interest for paleoclimate and source- to-sink reconstructions.", "entity1_score": 1.0, "entity2_score": 1.0, "entity1_label": "B-GeoPetro", "entity2_label": "B-GeoMeth", "entity1_nn_chunk": "a shale interval", "entity2_nn_chunk": "upstream", "file_path": "dummy_1_file.txt", "entity1_attnscore": 0.1, "entity2_attnscore": 0.09, "pair_attnscore": 0.09, "entity1_embedding": [3.913846731185913, -1.3515106439590454, 5.415563583374023, 9.736641883850098, 1.5567667484283447, 2.753096342086792, 2.371159076690674, 3.108031749725342, 1.6675533056259155, 12.004403114318848], "entity2_embedding": [3.9803621768951416, -0.6945693492889404, 6.077136993408203, 8.257105827331543, 2.2994720935821533, 4.3783793449401855, 1.7453073263168335, 3.397482395172119, 2.9937987327575684, 12.354580879211426], "sentence_embedding": [8.26601505279541, 2.053044557571411, 9.595142364501953, -2.32547926902771, 8.163567543029785, 9.313164710998535, -8.43984317779541, 3.634657859802246, 3.6852385997772217, 2.86068058013916]}', 'upstream'), 
           ('coarse', '{"context": "We suggest that climate and tectonic perturbations in the upstream North American catchments can induce a substantial response in the downstream sectors of the Gulf Coastal Plain and ultimately in the GoM. This relationship is illustrated in the deep-water basin by (1) a high accom- modation and deposition of a shale interval when coarse-grained terrigenous material was trapped upstream at the onset of the PETM, and (2) a considerable increase in sedi- ment supply during the PETM, which is archived as a particularly thick sedimentary section in the deep-sea fans of the GoM basin. Despite other thick PETM sections being observed elsewhere in the world, the one described in this study links with a continental- scale paleo-drainage, which makes it of particular interest for paleoclimate and source- to-sink reconstructions.", "entity1_score": 1.0, "entity2_score": 1.0, "entity1_label": "B-GeoPetro", "entity2_label": "B-GeoMeth", "entity1_nn_chunk": "coarse-grained terrigenous material", "entity2_nn_chunk": "upstream", "file_path": "dummy_1_file.txt", "entity1_attnscore": 0.05, "entity2_attnscore": 0.09, "pair_attnscore": 0.07, "entity1_embedding": [4.183037757873535, -0.95732182264328, 5.360871315002441, 10.020729064941406, 1.9280916452407837, 2.735372543334961, 2.475790023803711, 2.884106159210205, 2.3718998432159424, 11.750289916992188], "entity2_embedding": [4.050603866577148, -0.688696563243866, 6.089183807373047, 8.378361701965332, 2.33626127243042, 4.648577690124512, 1.70479416847229, 3.407353639602661, 3.1088290214538574, 12.333937644958496], "sentence_embedding": [8.26403522491455, 2.0533668994903564, 9.594727516174316, -2.3251283168792725, 8.122334480285645, 9.268819808959961, -8.390889167785645, 3.683662176132202, 3.695371150970459, 3.024846076965332]}', 'upstream'), 
           ('upstream', '{"context": "We suggest that climate and tectonic perturbations in the upstream North American catchments can induce a substantial response in the downstream sectors of the Gulf Coastal Plain and ultimately in the GoM. This relationship is illustrated in the deep-water basin by (1) a high accom- modation and deposition of a shale interval when coarse-grained terrigenous material was trapped upstream at the onset of the PETM, and (2) a considerable increase in sedi- ment supply during the PETM, which is archived as a particularly thick sedimentary section in the deep-sea fans of the GoM basin. Despite other thick PETM sections being observed elsewhere in the world, the one described in this study links with a continental- scale paleo-drainage, which makes it of particular interest for paleoclimate and source- to-sink reconstructions.", "entity1_score": 1.0, "entity2_score": 1.0, "entity1_label": "B-GeoMeth", "entity2_label": "B-GeoPetro", "entity1_nn_chunk": "upstream", "entity2_nn_chunk": "a particularly thick sedimentary section", "file_path": "dummy_1_file.txt", "entity1_attnscore": 0.09, "entity2_attnscore": 0.32, "pair_attnscore": 0.14, "entity1_embedding": [4.113377571105957, -0.4475870728492737, 6.095298767089844, 8.45187759399414, 2.4396491050720215, 4.143350601196289, 1.7025946378707886, 3.283315658569336, 2.8183791637420654, 12.168099403381348], "entity2_embedding": [4.4357590675354, -1.8888970613479614, 5.451931476593018, 9.404488563537598, 1.1754322052001953, 3.111313581466675, 2.1995394229888916, 3.109503746032715, 3.035334587097168, 12.325691223144531], "sentence_embedding": [8.266093254089355, 2.0530381202697754, 9.595128059387207, -2.3254902362823486, 8.218499183654785, 9.367105484008789, -8.362135887145996, 3.712357997894287, 3.6974105834960938, 2.9043288230895996]}', 'sedimentary'), 
           ('sedimentary', '{"context": "We suggest that climate and tectonic perturbations in the upstream North American catchments can induce a substantial response in the downstream sectors of the Gulf Coastal Plain and ultimately in the GoM. This relationship is illustrated in the deep-water basin by (1) a high accom- modation and deposition of a shale interval when coarse-grained terrigenous material was trapped upstream at the onset of the PETM, and (2) a considerable increase in sedi- ment supply during the PETM, which is archived as a particularly thick sedimentary section in the deep-sea fans of the GoM basin. Despite other thick PETM sections being observed elsewhere in the world, the one described in this study links with a continental- scale paleo-drainage, which makes it of particular interest for paleoclimate and source- to-sink reconstructions.", "entity1_score": 1.0, "entity2_score": 0.87, "entity1_label": "B-GeoPetro", "entity2_label": "B-GeoPetro, I-GeoPetro", "entity1_nn_chunk": "a particularly thick sedimentary section", "entity2_nn_chunk": "the deep-sea fans", "file_path": "dummy_1_file.txt", "entity1_attnscore": 0.32, "entity2_attnscore": 0.12, "pair_attnscore": 0.17, "entity1_embedding": [4.744527816772461, -1.797021508216858, 5.398539066314697, 9.334464073181152, 1.169188141822815, 3.1069962978363037, 2.099773645401001, 3.097820281982422, 2.888684034347534, 12.149800300598145], "entity2_embedding": [3.2142386436462402, -2.473020553588867, 5.727625846862793, 9.082856178283691, 2.1118242740631104, 2.521404266357422, 2.7171003818511963, 2.5763702392578125, 3.8491625785827637, 12.245673179626465], "sentence_embedding": [8.262020111083984, 2.053694725036621, 9.594340324401855, -2.3247909545898438, 7.908104419708252, 9.051258087158203, -8.493917465209961, 3.5807642936706543, 3.4950454235076904, 3.304839611053467]}', 'sea')], 
            0.6, 0.1, 0.5, 5, 3, 2, 5), ] )
    
# Async test function for TripleFilter
@pytest.mark.asyncio
async def test_triple_filter(triples, score_threshold, attention_score_threshold, similarity_threshold, min_cluster_size, min_samples, expected_filtered_count, expected_clustered_count):
    # Initialize the TripleFilter with the provided thresholds
    triple_filter = TripleFilter(
        score_threshold=score_threshold,
        attention_score_threshold=attention_score_threshold,
        similarity_threshold=similarity_threshold,
        min_cluster_size=min_cluster_size,
        min_samples=min_samples,
        cluster_persistence_threshold=0.4
    )
    cluster_output = triple_filter.cluster_triples(triples)
    clustered_triples = cluster_output['filtered_triples']
    cluster_labels = cluster_output['cluster_labels']
    cluster_persistence = cluster_output['cluster_persistence']
    cluster_reduction_count = cluster_output['reduction_count']
    assert cluster_reduction_count == expected_clustered_count
    assert len(clustered_triples) == len(triples) - expected_clustered_count
    final_clustered_triples = triple_filter.filter_by_cluster_persistence(triples, cluster_persistence, cluster_labels)
    assert len(final_clustered_triples) == 5
    filtered_triples, reduction_count = triple_filter.filter_triples(final_clustered_triples)
    assert reduction_count == expected_filtered_count
    assert len(filtered_triples) == len(final_clustered_triples) - expected_filtered_count
    

