diff --git a/DESCRIPTION b/DESCRIPTION index 7cab18f..d4a00cf 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,8 +21,6 @@ Imports: anytime, cli, dplyr, - ggplot2, - ggraph, glue, httr2, lifecycle, @@ -30,7 +28,6 @@ Imports: purrr, rlang, tibble, - tidygraph, WikidataQueryServiceR, WikidataR, xml2, diff --git a/R/glitter-package.R b/R/glitter-package.R index 1a4b751..f7d4732 100644 --- a/R/glitter-package.R +++ b/R/glitter-package.R @@ -1,4 +1,6 @@ #' @importFrom rlang `%||%` +#' @importFrom rlang `:=` +#' @importFrom rlang .data #' @keywords internal "_PACKAGE" diff --git a/R/graph_classes.R b/R/graph_classes.R deleted file mode 100644 index e73a810..0000000 --- a/R/graph_classes.R +++ /dev/null @@ -1,84 +0,0 @@ -#' Build the graph of sub/superclasses -#' @param id the id of class -#' @importFrom rlang .data `%||%` `:=` -#' @examples -#' \dontrun{ -#' tib_g=build_graph_classes("wd:Q627272") -#' } -#' @noRd -build_graph_classes=function(id){ - subclasses=subclasses_of(id,include_self=TRUE) - subclasses_start=subclasses - while(nrow(subclasses_start)!=0){ - subclasses_end=purrr::map_df(unique(subclasses_start$classes),subclasses_of) %>% - unique() - if(nrow(subclasses_end)>0){ - subclasses=dplyr::bind_rows(subclasses, - subclasses_end) - } - subclasses_start=subclasses_end - } - superclasses=superclasses_of(id,include_self=FALSE) - superclasses_start=superclasses - while(nrow(superclasses_start)!=0){ - superclasses_end=purrr::map_df(unique(superclasses_start$classes),superclasses_of) %>% - unique() - if(nrow(superclasses_end)>0){ - superclasses=dplyr::bind_rows(superclasses, - superclasses_end) - } - superclasses_start=superclasses_end - } - - table_edges=dplyr::bind_rows(subclasses %>% - dplyr::mutate(type=dplyr::case_when(.data$from==.data$to~"og", - .data$from!=.data$to~"sub")), - superclasses %>% - dplyr::mutate(type="sup")) - table_nodes=table_edges %>% - dplyr::select(.data$type, .data$classes, .data$classesLabel) %>% - unique() %>% - dplyr::mutate(n=count_items(.data$classes))%>% - dplyr::mutate(id=1:dplyr::n()) - table_edges=table_edges %>% - dplyr::select(from_wd=.data$from, - to_wd=.data$to) %>% - dplyr::left_join(table_nodes %>% - dplyr::select(.data$id,.data$classes), - by=c("to_wd"="classes")) %>% - dplyr::mutate(to=id) %>% - dplyr::select(-id) %>% - dplyr::left_join(table_nodes %>% dplyr::select(.data$id,.data$classes), - by=c("from_wd"="classes")) %>% - dplyr::mutate(from=id) %>% - dplyr::select(-.data$id) %>% - dplyr::select(.data$from,.data$to) %>% - stats::na.omit() %>% - dplyr::filter(.data$from!=.data$to) - tib_g=tidygraph::tbl_graph(nodes=table_nodes, - edges=table_edges) - return(tib_g) -} - -#' Show the graph of sub/superclasses -#' @param tib_g tib_g -#' @param layout layout of the graph for instance "kk" or "sugiyama" -#' @param n_min minimal number -#' @examples -#' \dontrun{ -#' tib_g=build_graph_classes("wd:Q627272") -#' show_graph_classes(tib_g,layout="kk") -#' show_graph_classes(tib_g,layout="sugiyama") -#' } -#' @noRd -show_graph_classes=function(tib_g,n_min=10,layout="kk"){ - tib_g_light=tib_g %>% - dplyr::filter(.data$n > {{ n_min }}) - g=ggraph::ggraph(tib_g_light, layout=layout) + - ggraph::geom_edge_link(arrow = ggplot2::arrow(length = ggplot2::unit(4, 'mm'))) + - ggraph::geom_node_label(ggplot2::aes(label=.data$classesLabel,size=log(.data$n),fill=.data$type),alpha=0.5)+ - ggplot2::coord_flip() - return(g) -} - - diff --git a/data-raw/.~lock.usual_endpoints.csv# b/data-raw/.~lock.usual_endpoints.csv# deleted file mode 100644 index 64d0312..0000000 --- a/data-raw/.~lock.usual_endpoints.csv# +++ /dev/null @@ -1 +0,0 @@ -,maelle,maelle-ZenBook-UX362FA-UX362FA,21.09.2023 13:30,file:///home/maelle/.config/libreoffice/4; \ No newline at end of file diff --git a/data-raw/pourmem.R b/data-raw/pourmem.R deleted file mode 100644 index c3a6e77..0000000 --- a/data-raw/pourmem.R +++ /dev/null @@ -1,74 +0,0 @@ -library(igraph) -library(tidygraph) -library(ggraph) -subclasses=readRDS("data-raw/subclasses.RDS") -get_from_id=function(id){ - tib=subclasses %>% - filter(from==id) %>% - mutate(type="below") - return(tib) -} -get_to_id=function(id){ - tib=subclasses %>% - filter(to==id) %>% - mutate(type="above") -} - - - -build_graph=function(id,step_max){ - df_start=tibble(NULL) - step=1 - df_end=bind_rows(get_from_id(id), - get_to_id(id)) %>% - mutate(step=step) - while(nrow(df_end)>nrow(df_start) & step% mutate(step=step), - from %>% mutate(step=step)) - } - - df_edges=df_end %>% - filter(step<=step_max) - df_nodes=df_edges %>% - select(classes,classesLabel,type) %>% - unique() %>% - mutate(id=1:n()) - - df_edges=df_edges %>% - select(from_wd=from, - to_wd=to) %>% - left_join(df_nodes %>% select(id,classes), - by=c("to_wd"="classes")) %>% - mutate(to=id) %>% - select(-id) %>% - left_join(df_nodes %>% select(id,classes), - by=c("from_wd"="classes")) %>% - mutate(from=id) %>% - select(-id) %>% - select(from,to) %>% - stats::na.omit() %>% - filter(from!=to) - - tib_g=tbl_graph(nodes=df_nodes, - edges=df_edges, - directed=TRUE) - return(tib_g) -} - -show_graph=function(tib_g,layout="sugiyama"){ - p=ggraph(tib_g, layout=layout) + - geom_edge_link(arrow = arrow(length = unit(4, 'mm'))) + - geom_node_label(aes(label=classesLabel, - #size=log(n), - fill=type),alpha=0.5)+ - coord_flip() - return(p) -} -tib_g=build_graph(id="wd:Q431603",step_max=3,layout="kk") -show_graph(tib_g) -#