Skip to content

Commit

Permalink
Adicionando nova assinatura e atualizando Ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
opauloxavier committed Oct 28, 2018
1 parent 99c6542 commit c68c5a6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
datasets/*
/.DS_Store
.DS_Store
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
julia 1.0
Persa
DataFrames
24 changes: 24 additions & 0 deletions src/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,32 @@ struct DatasetContext{T <: Number} <: Persa.AbstractDataset{T}
end


function DatasetContext(df::DataFrame)
context = Dict{Symbol,DataType}()

for (colname) in eachcol(df)
if colname != :user && colname != :item && colname != :rating
push!(context, colname => eltype(df[colname]))
end
end

DatasetContext(df,context)
end

DatasetContext(df::DataFrame, metaContextData::Dict) = DatasetContext(df, Persa.Dataset(df), metaContextData)

Base.string(x::DatasetContext) = string("""Context Aware Collaborative Filtering Dataset
- # users: $(Persa.users(x))
- # items: $(Persa.items(x))
- # ratings: $(Persa.length(x))
- # contexts: $(length(context(x)))
- # contextColumns: $([string(key) for key in collect(ContextCF.context(x))])
- Ratings Preference: $(x.preference)
""")

Base.print(io::IO, x::DatasetContext) = print(io, string(x))
Base.show(io::IO, x::DatasetContext) = print(io, x)

function DatasetContext(df::DataFrame, contextColumn::Vararg{Symbol})
metaContextData = Dict{Symbol,DataType}()
for context in contextColumn
Expand Down
5 changes: 2 additions & 3 deletions src/rating.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ struct ContextRating{T <: Number} <: Persa.AbstractRating{T}
ContextRating(x::T, preference::Persa.Preference{T}, context::Dict{Symbol,Any}) where T <: Number = new{T}(Persa.correct(x, preference), context)
end

Base.isnan(rating::ContextRating{T}) where T <: Number = false
Base.isnan(rating::Persa.MissingRating{T}) where T <: Number = true

Persa.Base.isnan(rating::ContextRating{T}) where T <: Number = false
Persa.Base.isnan(rating::Persa.MissingRating{T}) where T <: Number = true
Base.zero(::Type{ContextRating{T}}) where T <: Number = Persa.MissingRating{T}()

value(rating::ContextRating) = rating.value
Expand Down

0 comments on commit c68c5a6

Please sign in to comment.