Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

first commit

  • Loading branch information...
commit 31cd8570a2aeffbcf93566ebbcc4d3ce4196639c 1 parent 5c6c2b1
Maxime Demolin authored

Showing 1 changed file with 89 additions and 0 deletions. Show diff stats Hide diff stats

  1. +89 0 S2/Programmation/TD5/extraction.pl
89 S2/Programmation/TD5/extraction.pl
... ... @@ -0,0 +1,89 @@
  1 +#!/usr/bin/env perl
  2 +use strict;
  3 +use warnings;
  4 +use utf8;
  5 +binmode(STDIN, 'utf8');
  6 +binmode(STDERR, 'utf8');
  7 +binmode(STDOUT, 'utf8');
  8 +
  9 +=pod
  10 +
  11 +=head1 NAME
  12 +
  13 +B<TreeTagger: extraction>
  14 +
  15 +Extracts verbs or adjectives from a TreeTagger output
  16 +
  17 +=head1 Synopsis
  18 +
  19 +=over
  20 +
  21 +=item @present_forms = &search_verb($file,$verb_form)
  22 +
  23 +List verbs in file
  24 +
  25 +=item @present_adj = &search_adj($file)
  26 +
  27 +List adjective in file
  28 +
  29 +=back
  30 +=cut
  31 +
  32 +my $file = "treetagger.txt.tag" ;
  33 +my $lookfor = "faire" ;
  34 +
  35 +# get the list of verbs where form is $look_for
  36 +my @present_forms = &search_verb($file,$lookfor);
  37 +
  38 +# print output
  39 +if (scalar(@present_forms) > 0) {
  40 + print "Les formes de \"$lookfor\" présentes dans le texte sont :\n";
  41 + print join(", ", @present_forms) . "\n";
  42 +}
  43 +
  44 +
  45 +# get the list of adjectives
  46 +my @present_adj = &search_adj($file);
  47 +
  48 +# print output
  49 +if (scalar(@present_adj) > 0) {
  50 + print "Les adjectifs présents dans le texte sont :\n";
  51 + print join(", ", @present_adj) . "\n";
  52 +}
  53 +
  54 +sub search_verb {
  55 + my ($file,$lookfor) = @_ ;
  56 + my @present ;
  57 +
  58 + open(FILE, '<', $file) or die;
  59 + while (<FILE>) {
  60 + my @line = split(/\t/, $_) ;
  61 + # remove windows CRLF
  62 + $line[2] =~ s!\r\n!! ;
  63 + if ($line[2] eq $lookfor) {
  64 + push @present, $line[0];
  65 + }
  66 + }
  67 +
  68 + close(FILE);
  69 +
  70 + return @present;
  71 +}
  72 +
  73 +
  74 +sub search_adj {
  75 + my ($file) = @_ ;
  76 + my @present ;
  77 +
  78 + open(FILE, '<', $file) or die;
  79 + while (<FILE>) {
  80 + my @line = split(/\t/, $_) ;
  81 + if ($line[1] eq 'ADJ') {
  82 + push @present, $line[0];
  83 + }
  84 + }
  85 +
  86 + close(FILE);
  87 +
  88 + return @present;
  89 +}

0 comments on commit 31cd857

Please sign in to comment.
Something went wrong with that request. Please try again.