Guest User

Untitled

a guest
Jun 24th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <tweets>
  3. <tweet>
  4. <content>hola, bonita </content>
  5. </tweet>
  6. <tweet>
  7. <content>hola, dictadura </content>
  8. </tweet>
  9. </tweets>
  10.  
  11. my %hashcorpus = (
  12. dictadura => "nombre",
  13. bonita => "adjetivo", );
  14.  
  15. #!/usr/bin/perl
  16. use warnings;
  17. use strict;
  18. use utf8;
  19. use XML::LibXML;
  20.  
  21. my $filename = 'corpus.xml';
  22. my $dom = XML::LibXML->load_xml(location => $filename);
  23. foreach my $tweet ($tom->findnodes('//tweet'))
  24. {
  25. my @content = $tweet->findnodes('./content');
  26. die "<tweet> didn't have exactly one <content>: $tweet"
  27. unless @content==1;
  28.  
  29. my $content = $content[0]->textContent;
  30.  
  31. foreach my $key (keys %hash)
  32. {
  33. my $content =~ s/ $key / $hashcorpus{$key} /g;
  34. }
  35.  
  36. $content[0]->removeChildNodes();
  37. $content[0]->appendText($content);
  38. #~ #say $content;
  39.  
  40. }
  41.  
  42. print $tom->toString;
Add Comment
Please, Sign In to add comment