CaCORE

 view release on metacpan or  search on metacpan

examples/EVStest.pl  view on Meta::CPAN

#!/usr/bin/perl -w

use strict;

use LWP::UserAgent;
use HTTP::Request::Common;
use CaCORE::ApplicationService;
use CaCORE::EVS;

#
# ApplicationService is a utility classs that encapsulates webservice invocation to caCORE server.
# ApplicationService object follows the Singleton pattern, in that each program will ONLY contain one instance
# of such class.
# The URL being passed to the intance method is the service endpoint of the caCORE webservice.
# If no such URL is provided in the program, it will default to the caCORE production server, "http://cabio.nci.nih.gov/cacore30/ws/caCOREService"
#
my $appsvc = CaCORE::ApplicationService->instance("http://cabio.nci.nih.gov/cacore32/ws/caCOREService");

my $num2 = 0;

# test EVS 1: Search Metaphrase by Atom and Source
#
# This test case retrieves a MetaThesaurusConcept with a atom with code "1256-5501", and a source with abbrieviation "CSP2004"
#
print "test EVS 1 -- Search Metaphrase by Atom and Source\n";
# contruct search criteria
# First create an Atom object and sets its code attribute
my $atom = new CaCORE::EVS::Atom;
$atom->setCode("1256-5501");
my @atoms = ();
push @atoms, $atom;
# Second create a Source object and sets its abbreviation attributes
my $source = new CaCORE::EVS::Source;
$source->setAbbreviation("CSP2005");
my @sources = ($source);
# create a MetaThesaurusConcept instance and sets its Atom and Source relations
my $mtc = new CaCORE::EVS::MetaThesaurusConcept;
$mtc->setAtomCollection(@atoms);
$mtc->setSourceCollection(@sources);
my @mtcResults;
# the eval...warn... construct is recommended, if error is encountered during webservice call, this will
# trap the exception and allows for error handling, and prevent the program from exiting.
eval{
	#
	# This call encapsulates the webservice invocation to the caCORE server, and converts
	# the returned XML into list of MetaThesaurusConcept objects
	# Parameter 1 indicates target class, MetaThesaurusConcept, to be retrieved
	# Parameter 2 indicates search criteria. In this case, MetaThesaurusConcept with cetain Atoms and Sources.
	#
	@mtcResults = $appsvc->queryObject("CaCORE::EVS::MetaThesaurusConcept", $mtc);
};
warn "Test EVS 1 failed. Error:\n" . $@ if $@;
# iterate through results
foreach my $metaConcept (@mtcResults) {
	print "MetaThesaurusConcept: cui=" . $metaConcept->getCui . ", name=" . $metaConcept->getName . "\n";
}
$num2 = $#mtcResults + 1;
print "number of result: " . $num2 . "\n";

# test EVS 2: Search matching DescLogicConcepts for a MetaThesaurusConcept.
#
# This test case searches for matching DescLogicConcepts given a MetaThesaurusConcept.
#
print "test EVS 2 -- Search matching DescLogicConcepts for a MetaThesaurusConcept.\n";
my @dlcSet;
eval{



( run in 1.621 second using v1.01-cache-2.11-cpan-5837b0d9d2c )