Skip to content

Commit

Permalink
Merge pull request #12 from JuliaText/ox/oseven
Browse files Browse the repository at this point in the history
Update to 0.7
  • Loading branch information
oxinabox authored Jan 13, 2019
2 parents ee4a0c3 + b6d8761 commit 168671e
Show file tree
Hide file tree
Showing 18 changed files with 178 additions and 189 deletions.
13 changes: 3 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,15 @@ os:
- linux
- osx
julia:
- 0.6
- 0.7
- 1.0
- nightly
notifications:
email: false
git:
depth: 99999999

matrix:
allow_failures:
- julia: nightly


script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
script:
- julia -e 'Pkg.clone(pwd()); Pkg.build("WordNet")'
- julia -e 'Pkg.test("WordNet"; coverage=true)'
after_success:
- julia -e 'cd(Pkg.dir("WordNet")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Coverage Status](https://coveralls.io/repos/jbn/WordNet.jl/badge.svg?branch=master&service=github)](https://coveralls.io/github/jbn/WordNet.jl?branch=master)
[![Build status](https://ci.appveyor.com/api/projects/status/bpqbdf24thkp6ytw/branch/master?svg=true)](https://ci.appveyor.com/project/jbn/wordnet-jl/branch/master)

A Julia package for using Princeton's [WordNet](https://wordnet.princeton.edu/)®, heavily inspired by [Douches](https://github.com/doches)' [rwordnet](https://github.com/doches/rwordnet).
A Julia package for using Princeton's [WordNet](https://wordnet.princeton.edu/)®, heavily inspired by [Doches](https://github.com/doches)' [rwordnet](https://github.com/doches/rwordnet).

## Simple Demo

Expand All @@ -22,34 +22,34 @@ lemma = db['a', "glad"]
```julia
ss = synsets(db, lemma)
```
> 4-element Array{WordNet.Synset,1}:
> (a) glad (showing or causing joy and pleasure; especially made happy; "glad you are here"; "glad that they succeeded"; "gave a glad shout"; "a glad smile"; "heard the glad news"; "a glad occasion")
> (s) happy, glad (eagerly disposed to act or to be of service; "glad to help")
> (s) glad (feeling happy appreciation; "glad of the fire's warmth")
> (s) glad, beaming (cheerful and bright; "a beaming smile"; "a glad May morning")
> 4-element Array{WordNet.Synset,1}:
> (a) glad (showing or causing joy and pleasure; especially made happy; "glad you are here"; "glad that they succeeded"; "gave a glad shout"; "a glad smile"; "heard the glad news"; "a glad occasion")
> (s) happy, glad (eagerly disposed to act or to be of service; "glad to help")
> (s) glad (feeling happy appreciation; "glad of the fire's warmth")
> (s) glad, beaming (cheerful and bright; "a beaming smile"; "a glad May morning")
```julia
antonyms(db, ss[1])
```
> 1-element Array{WordNet.Synset,1}:
> 1-element Array{WordNet.Synset,1}:
> (a) sad (experiencing or showing sorrow or unhappiness; "feeling sad because his dog had died"; "Better by far that you should forget and smile / Than that you should remember and be sad"- Christina Rossetti)
```julia
expanded_hypernyms(db, synsets(db, db['n', "DOG"])[1])
```
> 13-element Array{WordNet.Synset,1}:
> (n) canine, canid (any of various fissiped mammals with nonretractile claws and typically long muzzles)
> (n) carnivore (a terrestrial or aquatic flesh-eating mammal; "terrestrial carnivores have four or five clawed digits on each limb")
> (n) eutherian mammal, placental, placental mammal, eutherian (mammals having a placenta; all mammals except monotremes and marsupials)
> (n) mammalian, mammal (any warm-blooded vertebrate having the skin more or less covered with hair; young are born alive except for the small subclass of monotremes and nourished with milk)
> (n) vertebrate, craniate (animals having a bony or cartilaginous skeleton with a segmented spinal column and a large brain enclosed in a skull or cranium)
> (n) chordate (any animal of the phylum Chordata having a notochord or spinal column)
> (n) animal, creature, animate being, brute, beast, fauna (a living organism characterized by voluntary movement)
> (n) organism, being (a living thing that has (or can develop) the ability to act or function independently)
> (n) living thing, animate thing (a living (or once living) entity)
> (n) unit, whole (an assemblage of parts that is regarded as a single entity; "how big is that part compared to the whole?"; "the team is a unit")
> (n) physical object, object (a tangible and visible entity; an entity that can cast a shadow; "it was full of rackets, balls and other objects")
> (n) physical entity (an entity that has physical existence)
> 13-element Array{WordNet.Synset,1}:
> (n) canine, canid (any of various fissiped mammals with nonretractile claws and typically long muzzles)
> (n) carnivore (a terrestrial or aquatic flesh-eating mammal; "terrestrial carnivores have four or five clawed digits on each limb")
> (n) eutherian mammal, placental, placental mammal, eutherian (mammals having a placenta; all mammals except monotremes and marsupials)
> (n) mammalian, mammal (any warm-blooded vertebrate having the skin more or less covered with hair; young are born alive except for the small subclass of monotremes and nourished with milk)
> (n) vertebrate, craniate (animals having a bony or cartilaginous skeleton with a segmented spinal column and a large brain enclosed in a skull or cranium)
> (n) chordate (any animal of the phylum Chordata having a notochord or spinal column)
> (n) animal, creature, animate being, brute, beast, fauna (a living organism characterized by voluntary movement)
> (n) organism, being (a living thing that has (or can develop) the ability to act or function independently)
> (n) living thing, animate thing (a living (or once living) entity)
> (n) unit, whole (an assemblage of parts that is regarded as a single entity; "how big is that part compared to the whole?"; "the team is a unit")
> (n) physical object, object (a tangible and visible entity; an entity that can cast a shadow; "it was full of rackets, balls and other objects")
> (n) physical entity (an entity that has physical existence)
> (n) entity (that which is perceived or known or inferred to have its own distinct existence (living or nonliving))
```julia
Expand All @@ -72,7 +72,7 @@ sensekeys(db, db['n', "cat"])

## Design consideration
This package loads all of WordNet into memory. It's not terribly expensive, but it may not be suitable for all developers.
This package loads all of WordNet into memory. It's not terribly expensive, but it may not be suitable for all developers.

## Wordnet Data
The constructor `DB` can optionally take a path to a WordNet directory, containing a `dict` folder.
Expand All @@ -81,5 +81,5 @@ If you do not specify such a path, WordNet 3.0 will automatically be downloaded
It will only be downloaded once.
See [DataDeps.jl's readme for more information](https://github.com/oxinabox/DataDeps.jl).

> George A. Miller (1995). WordNet: A Lexical Database for English.
> Communications of the ACM Vol. 38, No. 11: 39-41.
> George A. Miller (1995). WordNet: A Lexical Database for English.
> Communications of the ACM Vol. 38, No. 11: 39-41.
7 changes: 3 additions & 4 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
julia 0.6
Compat
FactCheck
DataDeps 0.3
julia 0.7
DataDeps 0.5

43 changes: 21 additions & 22 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
- julia_version: 0.7
- julia_version: 1
- julia_version: nightly

## uncomment the following lines to allow failures on nightly julia
## (tests will run but not make your overall status red)
platform:
- x86 # 32-bit
- x64 # 64-bit

# Uncomment the following lines to allow failures on nightly julia
# (tests will run but not make your overall status red)
matrix:
allow_failures:
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"


- julia_version: nightly

branches:
only:
Expand All @@ -26,19 +26,18 @@ notifications:
on_build_status_changed: false

install:
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$env:JULIA_URL,
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))

build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"WordNet\"); Pkg.build(\"WordNet\")"
- echo "%JL_BUILD_SCRIPT%"
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"

test_script:
- C:\projects\julia\bin\julia --check-bounds=yes -e "Pkg.test(\"WordNet\")"
- echo "%JL_TEST_SCRIPT%"
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"

# # Uncomment to support code coverage upload. Should only be enabled for packages
# # which would have coverage gaps without running on Windows
# on_success:
# - echo "%JL_CODECOV_SCRIPT%"
# - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%"
1 change: 0 additions & 1 deletion src/WordNet.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module WordNet

using Compat
using DataDeps

include("init.jl")
Expand Down
10 changes: 5 additions & 5 deletions src/constants.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
SYNSET_TYPES = @compat Dict{Char, AbstractString}(
SYNSET_TYPES = Dict{Char, String}(
'n' => "noun", 'v' => "verb", 'a' => "adj", 'r' => "adv"
)

NOUN_POINTERS = @compat Dict{AbstractString, AbstractString}(
NOUN_POINTERS = Dict{String, String}(
"-c" => "Member of this domain - TOPIC",
"+" => "Derivationally related form",
"%p" => "Part meronym",
Expand All @@ -23,7 +23,7 @@ NOUN_POINTERS = @compat Dict{AbstractString, AbstractString}(
"@i" => "Instance Hypernym",
"#m" => "Member holonym"
)
VERB_POINTERS = @compat Dict{AbstractString, AbstractString}(
VERB_POINTERS = Dict{String, String}(
"+" => "Derivationally related form",
"@" => "Hypernym",
";r" => "Domain of synset - REGION",
Expand All @@ -36,7 +36,7 @@ VERB_POINTERS = @compat Dict{AbstractString, AbstractString}(
"*" => "Entailment"
)

ADJECTIVE_POINTERS = @compat Dict{AbstractString, AbstractString}(
ADJECTIVE_POINTERS = Dict{String, String}(
";r" => "Domain of synset - REGION",
"!" => "Antonym",
"\\" => "Pertainym (pertains to noun)",
Expand All @@ -46,7 +46,7 @@ ADJECTIVE_POINTERS = @compat Dict{AbstractString, AbstractString}(
";c" => "Domain of synset - TOPIC"
)

ADVERB_POINTERS = @compat Dict{AbstractString, AbstractString}(
ADVERB_POINTERS = Dict{String, String}(
";r" => "Domain of synset - REGION",
"!" => "Antonym",
";u" => "Domain of synset - USAGE",
Expand Down
26 changes: 13 additions & 13 deletions src/db.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export DB

immutable DB
lemmas::Dict{Char, Dict{AbstractString, Lemma}}
struct DB
lemmas::Dict{Char, Dict{String, Lemma}}
synsets::Dict{Char, Dict{Int, Synset}}
sensekeys::Dict{Tuple{Int, AbstractString}, AbstractString}
sensekeys::Dict{Tuple{Int, String}, String}
end

function DB(base_dir::AbstractString=datadep"WordNet 3.0")
Expand All @@ -23,19 +23,19 @@ end
Base.getindex(db::DB, word::AbstractString, pos::Char) = db[pos, word]

function load_lemmas(base_dir)
lemmas = Dict{Char, Dict{AbstractString, Lemma}}()
lemmas = Dict{Char, Dict{String, Lemma}}()

for pos in ['n', 'v', 'a', 'r']
d = Dict{AbstractString, Lemma}()
d = Dict{String, Lemma}()

open(path_to_index_file(base_dir, pos)) do f
for (i, line) in enumerate(eachline(f))
i > 29 || continue # Skip Copyright.
word = line[1:(search(line, ' ')-1)]
word = line[1:(findfirst(isequal(' '), line) - 1)]
d[word] = Lemma(line, i-29)
end
end

lemmas[pos] = d
end

Expand All @@ -44,7 +44,7 @@ end

function load_synsets(base_dir)
synsets = Dict{Char, Dict{Int, Synset}}()

for pos in ('n', 'v', 'a', 'r')
d = Dict{Int, Synset}()

Expand All @@ -58,15 +58,15 @@ function load_synsets(base_dir)

synsets[pos] = d
end

synsets
end


function load_sensekeys(basedir)
path=joinpath(basedir, "dict", "index.sense")
sensekeys = Dict{Tuple{Int64, AbstractString}, AbstractString}()
sensekeys = Dict{Tuple{Int64, String}, String}()

for line in eachline(path)
full_key, offset_str, sense_num_str, tagcount_str = split(line)
lemma_name = first(split(full_key, '%'))
Expand All @@ -75,7 +75,7 @@ function load_sensekeys(basedir)
@assert(!haskey(sensekeys, index))
sensekeys[index] = full_key
end

sensekeys
end

Expand Down
20 changes: 10 additions & 10 deletions src/lemma.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@ export Lemma

const SPACE = ' '

immutable Lemma
word::AbstractString
struct Lemma
word::String
pos::Char
tagsense_count::Int
synset_offsets::Vector{Int}
id::Int
pointer_syms::Vector{AbstractString}
pointer_syms::Vector{String}
end

function Lemma(lexicon_line, id)
parts = split(lexicon_line, SPACE)

word = shift!(parts)
pos = shift!(parts)[1]
synset_count = parse(Int, shift!(parts))

n_syms = parse(Int, shift!(parts))
word = popfirst!(parts)
pos = popfirst!(parts)[1]
synset_count = parse(Int, popfirst!(parts))

n_syms = parse(Int, popfirst!(parts))
pointer_syms = [s for s in parts[1:n_syms]]
parts = parts[n_syms+2:end]

tagsense_count = parse(Int, shift!(parts))
tagsense_count = parse(Int, popfirst!(parts))
synset_offsets = [parse(Int, c) for c in parts[1:synset_count]]

Lemma(word, pos, tagsense_count, synset_offsets, id, pointer_syms)
end

Expand Down
2 changes: 1 addition & 1 deletion src/operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ hypernyms(db::DB, synset::Synset) = get(relation(db, synset, HYPERNYM), 1, ∅)
hyponyms(db::DB, synset::Synset) = relation(db, synset, HYPONYM)

function expanded_hypernyms(db::DB, synset::Synset)
path = @compat Vector{Synset}()
path = Vector{Synset}()

node = hypernyms(db, synset)
while !is_nothing(node)
Expand Down
8 changes: 4 additions & 4 deletions src/pointer.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
immutable Pointer
sym::AbstractString
struct Pointer
sym::String
offset::UInt32
pos::Char
source::AbstractString
target::AbstractString
source::String
target::String
end

Pointer(sym, offset, pos, source) = Pointer(
Expand Down
Loading

0 comments on commit 168671e

Please sign in to comment.