Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:berkmancenter/mediacloud
Browse files Browse the repository at this point in the history
  • Loading branch information
hroberts committed May 15, 2014
2 parents a17b056 + 36f3a6b commit 0ba149e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 61 deletions.
9 changes: 0 additions & 9 deletions lib/CRF/CrfUtils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,6 @@ sub create_model($$)
return $module->create_model( $training_data_file, $iterations );
}

sub run_model($$$)
{
my ( $model_file_name, $test_data_file, $output_fhs ) = @_;

my $module = _load_and_return_crf_module();

return $module->run_model( $model_file_name, $test_data_file, $output_fhs );
}

sub run_model_inline_java_data_array($$)
{
my ( $model_file_name, $test_data_array ) = @_;
Expand Down
30 changes: 0 additions & 30 deletions lib/CRF/CrfUtils/InlineJava.pm
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,6 @@ sub create_model($$$)
return _create_model_inline_java( $class, $training_data_file, $iterations );
}

sub run_model($$$$)
{
my ( $class, $model_file_name, $test_data_file, $output_fhs ) = @_;

return _run_model_inline_java( $class, $model_file_name, $test_data_file, $output_fhs );
}

sub run_model_inline_java_data_array($$$)
{
my ( $class, $model_file_name, $test_data_array ) = @_;
Expand Down Expand Up @@ -174,29 +167,6 @@ sub _run_model_on_array($$$)
return $results;
}

sub _run_model_inline_java($$$$)
{
my ( $class, $model_file_name, $test_data_file, $output_fhs ) = @_;

my $probabilities_fh = $output_fhs->{ probabilities_fh };

my $predictions_fh = $output_fhs->{ predictions_fh };

my $expected_results_fh = $output_fhs->{ expected_results_fh };

say STDERR "generating predictions";

say STDERR "classpath: $class_path";

my @test_data_array = read_file( $test_data_file );

my $foo = run_model_inline_java_data_array( $class, $model_file_name, \@test_data_array );

say join "\n", @{ $foo };

exit();
}

sub _crf_modelrunner_java_src()
{
# Compile and prepare Java class from /java/CrfUtils/
Expand Down
8 changes: 0 additions & 8 deletions lib/CRF/CrfUtils/WebService.pm
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@ sub create_model($$$)
_fatal_error( "Not implemented in " . __PACKAGE__ );
}

sub run_model($$$$)
{
my ( $class, $model_file_name, $test_data_file, $output_fhs ) = @_;

# Clients should use CRF::CrfUtils::InlineJava directly
_fatal_error( "Not implemented in " . __PACKAGE__ );
}

sub run_model_inline_java_data_array($$$)
{
my ( $class, $model_file_name, $test_data_array ) = @_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,13 @@ public ModelRunner(String modelFileName) throws IOException,
p.getDataAlphabet().stopGrowth();
}

public String[] runModel(String testFileName) throws Exception {
private String[] runModel(String testFileName) throws Exception {

InstanceList testData = readTestData(testFileName);
return crfOutputsToStrings(runCrfModel(testData));
}

public String runModelReturnString(String testFileName) throws Exception {

String[] results = runModel(testFileName);
return joinArrayToString("\n", results);
}

public String[] runModelString(String testDataString) throws Exception {
String[] runModelString(String testDataString) throws Exception {

InstanceList testData = readTestDataFromString(testDataString);
return crfOutputsToStrings(runCrfModel(testData));
Expand All @@ -72,17 +66,14 @@ private ArrayList<CrfOutput> runCrfModel(InstanceList testData) {
System.err.println("Max Memory: " + rt.maxMemory() / 1024 + " KB");
System.err.println("");
*/
ArrayList<String> results = new ArrayList<String>();

if ( testData.size() > 1) {
if ( testData.size() > 1) {
throw new IllegalArgumentException("test data may only contain one sequence");
}

Sequence input = (Sequence) testData.get(0).getData();

ArrayList<CrfOutput> crfResults = predictSequence(input);

return crfResults;
return predictSequence(input);

//return crfOutputsToStrings(crfResults);
}
Expand All @@ -95,7 +86,7 @@ private String[] crfOutputsToStrings(ArrayList<CrfOutput> crfResults) {
sequenceResults.add( crfResult.prediction + " ");
}

return sequenceResults.toArray(new String[0]);
return sequenceResults.toArray(new String[sequenceResults.size()]);
}

private InstanceList readTestData(String testFileName) throws FileNotFoundException {
Expand Down

0 comments on commit 0ba149e

Please sign in to comment.