Skip to content

Commit 05eae3c

Browse files
committed
remove condition to have zero subjects to run 'enrichWithSubjects
1 parent cf16071 commit 05eae3c

File tree

1 file changed

+57
-60
lines changed

1 file changed

+57
-60
lines changed

R/geoflow_entity.R

Lines changed: 57 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,67 +1869,64 @@ geoflow_entity <- R6Class("geoflow_entity",
18691869
#'automatically add keyword from dictionary to 'theme' category
18701870
#'@param config geoflow config object
18711871
enrichWithSubjects = function(config){
1872-
1873-
if(length(self$subjects)==0){
1874-
1875-
data_objects <- self$data
1876-
if(is(data_objects, "geoflow_data")) data_objects <- list(self$data)
1877-
1878-
if(length(data_objects)>0) for(k in 1:length(data_objects)){
1879-
1880-
data_object = data_objects[[k]]
18811872

1882-
#List all columns of data features
1883-
columns <- colnames(data_object$features)
1884-
for(featureAttrName in columns){
1885-
#Check if correspond column exist in dictionary
1886-
fat_attr <- NULL
1887-
fto <- data_object$featureTypeObj
1888-
if(!is.null(fto)) fat_attr <- fto$getMemberById(featureAttrName)
1889-
if(!is.null(fat_attr)){
1890-
#Check if register is link
1891-
registerId <- fat_attr$registerId
1892-
1893-
if(!is.null(registerId)) if(!is.na(registerId)){
1894-
registers <- config$registers
1895-
if(length(registers)>0) {
1896-
registers <- registers[sapply(registers, function(x){x$id == registerId})]
1897-
fat_attr_register <- registers[[1]]
1898-
1899-
#Check if values of column are in register
1900-
dataAttrValues <- unique(data_object$features[featureAttrName])
1901-
featureAttrValues <- switch(class(data_object$features)[1],
1902-
"sf" = data_object$features[,featureAttrName][[1]],
1903-
"data.frame" = data_object$features[,featureAttrName]
1904-
)
1905-
featureAttrValues <- unique(featureAttrValues)
1906-
matchAttrValues <- subset(fat_attr_register$data, code %in% featureAttrValues)
1907-
1908-
if (nrow(matchAttrValues)>0){
1909-
defSource <- fat_attr$defSource
1910-
if(is.na(defSource)){desc_name<-paste0("[",fat_attr$name,"]")}else{
1911-
desc_name<-paste0("[",defSource[1],"]")
1912-
if(!is.null(attr(defSource,"description"))) desc_name<-paste0("[",attr(defSource,"description"),"]")
1913-
if(!is.null(attr(defSource,"uri"))) desc_name<-paste0(desc_name,"@",attr(defSource,"uri"))
1914-
}
1915-
subject_obj <- geoflow_subject$new()
1916-
subject_obj$setKey("theme")
1917-
subject_obj$setName(desc_name)
1918-
for(i in 1:nrow(matchAttrValues)){
1919-
subject_obj$addKeyword(
1920-
keyword = paste0(matchAttrValues$label[i]," [",matchAttrValues$code[i],"]"),
1921-
uri = if(!is.na(matchAttrValues$uri[i])) matchAttrValues$uri[i] else NULL
1922-
)
1923-
}
1924-
self$addSubject(subject_obj)
1925-
1926-
}
1927-
}
1928-
}
1929-
}
1930-
}
1931-
}
1932-
}
1873+
data_objects <- self$data
1874+
if(is(data_objects, "geoflow_data")) data_objects <- list(self$data)
1875+
1876+
if(length(data_objects)>0) for(k in 1:length(data_objects)){
1877+
1878+
data_object = data_objects[[k]]
1879+
1880+
#List all columns of data features
1881+
columns <- colnames(data_object$features)
1882+
for(featureAttrName in columns){
1883+
#Check if correspond column exist in dictionary
1884+
fat_attr <- NULL
1885+
fto <- data_object$featureTypeObj
1886+
if(!is.null(fto)) fat_attr <- fto$getMemberById(featureAttrName)
1887+
if(!is.null(fat_attr)){
1888+
#Check if register is link
1889+
registerId <- fat_attr$registerId
1890+
1891+
if(!is.null(registerId)) if(!is.na(registerId)){
1892+
registers <- config$registers
1893+
if(length(registers)>0) {
1894+
registers <- registers[sapply(registers, function(x){x$id == registerId})]
1895+
fat_attr_register <- registers[[1]]
1896+
1897+
#Check if values of column are in register
1898+
dataAttrValues <- unique(data_object$features[featureAttrName])
1899+
featureAttrValues <- switch(class(data_object$features)[1],
1900+
"sf" = data_object$features[,featureAttrName][[1]],
1901+
"data.frame" = data_object$features[,featureAttrName]
1902+
)
1903+
featureAttrValues <- unique(featureAttrValues)
1904+
matchAttrValues <- subset(fat_attr_register$data, code %in% featureAttrValues)
1905+
1906+
if (nrow(matchAttrValues)>0){
1907+
defSource <- fat_attr$defSource
1908+
if(is.na(defSource)){desc_name<-paste0("[",fat_attr$name,"]")}else{
1909+
desc_name<-paste0("[",defSource[1],"]")
1910+
if(!is.null(attr(defSource,"description"))) desc_name<-paste0("[",attr(defSource,"description"),"]")
1911+
if(!is.null(attr(defSource,"uri"))) desc_name<-paste0(desc_name,"@",attr(defSource,"uri"))
1912+
}
1913+
subject_obj <- geoflow_subject$new()
1914+
subject_obj$setKey("theme")
1915+
subject_obj$setName(desc_name)
1916+
for(i in 1:nrow(matchAttrValues)){
1917+
subject_obj$addKeyword(
1918+
keyword = paste0(matchAttrValues$label[i]," [",matchAttrValues$code[i],"]"),
1919+
uri = if(!is.na(matchAttrValues$uri[i])) matchAttrValues$uri[i] else NULL
1920+
)
1921+
}
1922+
self$addSubject(subject_obj)
1923+
1924+
}
1925+
}
1926+
}
1927+
}
1928+
}
1929+
}
19331930

19341931
#GEMET thesaurus (enrichment with proper publication dates)
19351932
if(any(sapply(self$subjects, function(subject){

0 commit comments

Comments
 (0)