ALBD

 view release on metacpan or  search on metacpan

lib/LiteratureBasedDiscovery/Filters.pm  view on Meta::CPAN

	    my $typesRef = $umls->getSt($cui);
	    foreach my $type(@{$typesRef}) {
		my $abr = $umls->getStAbr($type);

		#check the cui for removal
		if (exists ${$acceptTypesRef}{$type}) {
		    $cuisChecked{$cui} = 1;
		    last;
		}
	    }
	}

	#eliminate if needed
	if ($cuisChecked{$cui} < 0) {
	    delete ${$matrixRef}{$cui};
	}
    }

    #eliminate cuis from columns
    foreach my $cui1 (keys %{$matrixRef}) {
	foreach my $cui2 (keys %{${$matrixRef}{$cui1}}) {
	    #update cui checked hash
	    if (!exists $cuisChecked{$cui2}) {
		$cuisChecked{$cui2} = -1;

		my $typesRef = $umls->getSt($cui2);
		foreach my $type(@{$typesRef}) {
		    my $abr = $umls->getStAbr($type);

		    #check the cui for removal
		    if (exists ${$acceptTypesRef}{$type}) {
			$cuisChecked{$cui2} = 1;
			last;
		    }
		}
	    }

	    #eliminate if needed
	    if ($cuisChecked{$cui2} < 0) {
		delete ${${$matrixRef}{$cui1}}{$cui2};
	    }
	}
    }


=comment
    #Count the number of keys after filtering (for debugging)
    %termsHash = ();
    foreach my $key1 (keys %{$matrixRef}) {
	foreach my $key2 (keys %{${$matrixRef}{$key1}}) {
	    $termsHash{$key2} = 1;
	}
    }
    print "   number of keys after filtering = ".(scalar keys %termsHash)."\n";
=cut
}


# applies a semantic group filter to the matrix, by removing keys that 
# are not allowed semantic type. Only removes types from rows, 
# so is applied for times slicing, before randomly selecting terms of 
# one semantic type
# input:  $matrixRef <- ref to a sparse matrix to be filtered
#         $acceptTypesRef <- a ref to a hash of accept type strings
#         $umls <- an instance of UMLS::Interface
# output: None, but $vectorRef is updated 
sub semanticTypeFilter_rows {
    my $matrixRef = shift;
    my $acceptTypesRef = shift;
    my $umls = shift;
    
=comment
    #Count the number of keys before and after filtering (for debugging)
    my %termsHash = ();
    foreach my $key1 (keys %{$matrixRef}) {
	foreach my $key2 (keys %{${$matrixRef}{$key1}}) {
	    $termsHash{$key2} = 1;
	}
    }
    print "   number of keys before filtering = ".(scalar keys %termsHash)."\n";
=cut

    #eliminate values that are incorrect semantic groups
    #do each row at a time, remove column values that 
    #are the incorrect semantic type
    my $keep = -1;
    #cuisChecked keeps track of cuis that have been checked 
    # for elimination. If the cui has been checked its key
    # will exist in the hash. Values of -1 indicate it should
    # be eliminated, values of 1 indicate it should stay.
    #eliminate cuis from columns
    foreach my $cui1 (keys %{$matrixRef}) {
	my $typesRef = $umls->getSt($cui1);
	foreach my $type(@{$typesRef}) {
	    my $abr = $umls->getStAbr($type);

	    #check the cui for removal
	    if (exists ${$acceptTypesRef}{$type}) {
		$keep = 1;
		last;
	    }
	}

	#eliminate if needed
	if ($keep < 0) {
	    delete ${$matrixRef}{$cui1};
	}
	$keep = -1;
    }

=comment
    #Count the number of keys after filtering (for debugging)
    %termsHash = ();
    foreach my $key1 (keys %{$matrixRef}) {
	foreach my $key2 (keys %{${$matrixRef}{$key1}}) {
	    $termsHash{$key2} = 1;
	}
    }
    print "   number of keys after filtering = ".(scalar keys %termsHash)."\n";
=cut
}



( run in 1.154 second using v1.01-cache-2.11-cpan-fe3c2283af0 )