fix sentiment model

This commit is contained in:
Mike Innes 2018-09-14 18:10:24 +01:00
parent b93d4763cc
commit d797999fc5
2 changed files with 7 additions and 4 deletions

View File

@ -4,7 +4,7 @@ using ZipFile
using ..Data: deps
function load()
isfile(deps("sentiment.zip")) || return
isfile(deps("sentiment.zip")) && return
@info "Downloading sentiment treebank dataset"
download("https://cache.julialang.org/https://nlp.stanford.edu/sentiment/trainDevTestTrees_PTB.zip",
deps("sentiment.zip"))
@ -26,9 +26,10 @@ totree_(n, a, b) = Tree{Any}((parse(Int, n), nothing), totree(a), totree(b))
totree(t::Expr) = totree_(t.args...)
function parsetree(s)
s = replace(s, r"\$", s -> "\\\$")
s = replace(s, r"[^\s\(\)]+", s -> "\"$s\"")
s = replace(s, " ", ", ")
s = replace(s, "\\" => "")
s = replace(s, "\$" => "\\\$")
s = replace(s, r"[^ \n\(\)]+" => s -> "\"$s\"")
s = replace(s, " " => ", ")
return totree(Meta.parse(s))
end

View File

@ -9,3 +9,5 @@ using Test
@test MNIST.images()[1] isa Matrix
@test MNIST.labels() isa Vector{Int64}
@test Data.Sentiment.train() isa Vector{Data.Tree{Any}}