rudof_rdf/rdf_core/visualizer/utils/
usage_count.rs1use std::fmt::Display;
2
3pub struct UsageCount {
5 as_predicate: usize,
7 as_predicate_in_triple: usize,
9 as_subject: usize,
11 as_subject_in_triple: usize,
13 as_object: usize,
15 as_object_in_triple: usize,
17}
18
19impl UsageCount {
20 pub fn new() -> Self {
22 UsageCount {
23 as_predicate: 0,
24 as_subject: 0,
25 as_object: 0,
26 as_predicate_in_triple: 0,
27 as_subject_in_triple: 0,
28 as_object_in_triple: 0,
29 }
30 }
31
32 pub fn as_predicate(&self) -> usize {
34 self.as_predicate
35 }
36
37 pub fn as_subject(&self) -> usize {
39 self.as_subject
40 }
41
42 pub fn as_object(&self) -> usize {
44 self.as_object
45 }
46
47 pub fn in_triple(&self) -> bool {
49 self.as_predicate_in_triple > 0 || self.as_subject_in_triple > 0 || self.as_object_in_triple > 0
50 }
51
52 pub fn increment_as_predicate(&mut self) {
54 self.as_predicate += 1;
55 }
56
57 pub fn increment_as_subject(&mut self) {
59 self.as_subject += 1;
60 }
61
62 pub fn increment_as_object(&mut self) {
64 self.as_object += 1;
65 }
66
67 pub fn increment_as_predicate_in_triple(&mut self) {
69 self.as_predicate_in_triple += 1;
70 }
71
72 pub fn increment_as_subject_in_triple(&mut self) {
74 self.as_subject_in_triple += 1;
75 }
76
77 pub fn increment_as_object_in_triple(&mut self) {
79 self.as_object_in_triple += 1;
80 }
81}
82
83impl Display for UsageCount {
84 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
85 write!(
86 f,
87 "UsageCount {{ as_predicate: {}, as_subject: {}, as_object: {}, as_predicate_in_triple: {}, as_subject_in_triple: {}, as_object_in_triple: {} }}",
88 self.as_predicate,
89 self.as_subject,
90 self.as_object,
91 self.as_predicate_in_triple,
92 self.as_subject_in_triple,
93 self.as_object_in_triple
94 )
95 }
96}
97
98impl Default for UsageCount {
99 fn default() -> Self {
100 UsageCount::new()
101 }
102}