Copia First Run

Written on July 6, 2016

A draft of copia was executable today in Perl. I chose an API that I think I can work with. The problem is that the API hasn’t been updated in so many years (2012 or 2014), and so I’m afraid the API may already be depreciated – as I’m unsure how to troubleshoot the issue. I will note the issues below.

The code is a manipulated script from the Wiktionary::Parser - Client and Parser of content from the Wiktionary API. Here’s what I hacked to create the following output.

#! /usr/bin/env perl
#
# This example uses the get_synonyms() method to print out
# all synonyms for each word sense & language available
#
 
use warnings;
use strict;
use Data::Dumper;
 
use Wiktionary::Parser;
use Encode qw(encode);
 
my $word = \@ARGV;
my $parser = Wiktionary::Parser->new();
my $document = $parser->get_document(title => $word);
 
#
# The following methods return data in identical data structures:
#
# $document->get_synonyms()
# $document->get_hyponyms()
# $document->get_hypernyms()
# $document->get_antonyms();
#
#
# Note that for each of these, the document parser
# will follow any 'Wikisaurus' links and return data
# from the extended lists on those pages
 
my $synonyms = $document->get_synonyms();
 
for my $language_code (sort keys %{ $synonyms || {} }) {
 
	print "$synonyms->{$language_code}{language}; $language_code\n";
 
	for my $word_sense (sort keys %{ $synonyms->{$language_code}{sense} }) {
 
		print "\t$word_sense\n";
		
		my @words = @{ $synonyms->{$language_code}{sense}{$word_sense} };
 
		for my $word (@words) {
			print "\t\t$word\n";
		}
	}
}

Input:

~/copia$ perl -w test-5.pl exam

Output:

English; en
	academics
	challenge
Spanish; es
	ARRAY(0x8a5260)
		prueba
Dutch; nl
	ARRAY(0x8a5260)
		experiment
		proef
Swedish; sv
	ARRAY(0x8a5260)
		examen
		f�rs�k
		experiment
		prov
		skrivning
		tofs
		tuss

So far the issues that have popped up have been the following:

  1. Issue #6
  2. Non-English characters look like this: f�rs�k

TODO:

  1. Create definition for each word.
  2. Research on how the code works line by line.

Take me home.

Check out the archive.