embarrassment
clean(attr_df)
Clean attribute triple values.
Remove datatype tags and return values as string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr_df |
DataFrame
|
Attribute triples. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
Cleaned attribute triples. |
Examples:
>>> import pandas as pd
>>> attr = pd.DataFrame([("e1","attr1","'lorem ipsum'^^xsd:string"), ("e2","attr2","dolor")], columns=["head","relation","tail"])
>>> from embarrassment import clean
>>> clean(attr)
head relation tail
0 e1 attr1 lorem ipsum
1 e2 attr2 dolor
Source code in embarrassment/api.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
neighbor_attr_triples(rel_df, attr_df, wanted_eid, in_out_both='both')
Find attribute triples of neighbor entities of specific entity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rel_df |
DataFrame
|
Relation triples. |
required |
attr_df |
DataFrame
|
Attribute triples. |
required |
wanted_eid |
str
|
Wanted entity id of which the neighborhood is used. |
required |
in_out_both |
InOutBoth
|
Whether to look at ("in","out","both") edges. |
'both'
|
Returns:
Type | Description |
---|---|
DataFrame
|
Attribute triples of neighboring entities. |
Raises:
Type | Description |
---|---|
ValueError
|
if unknown in_out_both value. |
Examples:
>>> import pandas as pd
>>> rel = pd.DataFrame([("e1","rel1","e2"), ("e3", "rel2", "e1")], columns=["head","relation","tail"])
>>> attr = pd.DataFrame([("e1","attr1","lorem ipsum"), ("e2","attr2","dolor")], columns=["head","relation","tail"])
>>> from embarrassment import neighbor_attr_triples
>>> neighbor_attr_triples(rel, attr, "e1")
head relation tail
1 e2 attr2 dolor
Source code in embarrassment/api.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
|
neighbor_rel_triples(rel_df, wanted_eid, in_out_both='both', filter_self=True)
Find relation triples of immediate neighbors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rel_df |
DataFrame
|
Relation triples. |
required |
wanted_eid |
str
|
Wanted entity id, to search neighborhood. |
required |
in_out_both |
InOutBoth
|
Whether to look at ("in","out","both") edges. |
'both'
|
filter_self |
bool
|
Remove triples containing wanted entity id. |
True
|
Returns:
Type | Description |
---|---|
DataFrame
|
relation triples of immediate neighbors of search entity. |
Raises:
Type | Description |
---|---|
ValueError
|
if unknown in_out_both value. |
Examples:
>>> import pandas as pd
>>> rel = pd.DataFrame([("e1","rel1","e2"), ("e3", "rel2", "e1"), ("e3", "rel2", "e4"), ("e2", "rel2", "e4")], columns=["head","relation","tail"])
>>> from embarrassment import neighbor_rel_triples
>>> neighbor_rel_triples(rel, "e1")
head relation tail
2 e3 rel2 e4
3 e2 rel2 e4
>>> neighbor_rel_triples(rel, "e1", "in")
head relation tail
2 e3 rel2 e4
>>> neighbor_rel_triples(rel, "e1", "in", filter_self=False)
head relation tail
1 e3 rel2 e1
2 e3 rel2 e4
Source code in embarrassment/api.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
|
neighbor_set(rel_df, wanted_eid, in_out_both='both')
Get set of neighboring entities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rel_df |
DataFrame
|
Relation triples. |
required |
wanted_eid |
str
|
Entity id of which the neighborhood is investigated. |
required |
in_out_both |
InOutBoth
|
Whether to look at ("in","out","both") edges. |
'both'
|
Returns:
Type | Description |
---|---|
Set[str]
|
Set of neighboring ids. |
Raises:
Type | Description |
---|---|
ValueError
|
if unknown in_out_both value. |
Examples:
>>> import pandas as pd
>>> rel = pd.DataFrame([("e1","rel1","e2"), ("e3", "rel2", "e1")], columns=["head","relation","tail"])
>>> from embarrassment import neighbor_set
>>> neighbor_set(rel, "e1")
{'e2', 'e3'}
Source code in embarrassment/api.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
|
search(attr_df, query, method='exact')
Search for triples with values in attribute triples.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr_df |
DataFrame
|
Attribute triples. |
required |
query |
str
|
Query string. |
required |
method |
SearchMethod
|
Search method ("exact", "substring", "close"). |
'exact'
|
Returns:
Type | Description |
---|---|
DataFrame
|
Triples where tail matches query. |
Raises:
Type | Description |
---|---|
ValueError
|
if unknown search method. |
Examples:
>>> import pandas as pd
>>> attr = pd.DataFrame([("e1","attr1","lorem ipsum"), ("e2","attr2","dolor")], columns=["head","relation","tail"])
>>> from embarrassment import search
>>> search(attr, "lorem ipsum")
head relation tail
0 e1 attr1 lorem ipsum
>>> search(attr, "lorem", method="substring")
head relation tail
0 e1 attr1 lorem ipsum
Source code in embarrassment/api.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
|
select(trdf, query, hrt='head')
Select triples containing the queried id(s) in specified column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trdf |
DataFrame
|
Triple DataFrame. |
required |
query |
Union[Sequence[str], str]
|
Query id(s). |
required |
hrt |
str
|
head, relation or tail column name. |
'head'
|
Returns:
Type | Description |
---|---|
DataFrame
|
Triples containing the queried id(s) in specified column. |
Examples:
>>> import pandas as pd
>>> rel = pd.DataFrame([("e1","rel1","e2"), ("e3", "rel2", "e1")], columns=["head","relation","tail"])
>>> from embarrassment import select
>>> select(rel, "e1")
head relation tail
0 e1 rel1 e2
>>> select(rel, ["e1","e3"])
head relation tail
0 e1 rel1 e2
1 e3 rel2 e1
>>> select(rel, ["e1","e3"], hrt="tail")
head relation tail
1 e3 rel2 e1
Source code in embarrassment/api.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
select_by_type(rel_df, wanted_type, type_rel='http://www.w3.org/1999/02/22-rdf-syntax-ns#type')
Select triples by type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rel_df |
DataFrame
|
Triple DataFrame. |
required |
wanted_type |
str
|
Wanted type. |
required |
type_rel |
str
|
Type relation. |
'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'
|
Returns:
Type | Description |
---|---|
DataFrame
|
Triples with specified type. |
Examples:
>>> import pandas as pd
>>> rel = pd.DataFrame([("e1","http://www.w3.org/1999/02/22-rdf-syntax-ns#type","type2"), ("e3", "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", "type1")], columns=["head","relation","tail"])
>>> from embarrassment import select_by_type
>>> select_by_type(rel, "type1")
head relation tail
1 e3 http://www.w3.org/1999/02/22-rdf-syntax-ns#type type1
Source code in embarrassment/api.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
|
select_rel(trdf, rel)
Select triples with specific relation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trdf |
DataFrame
|
Triple DataFrame. |
required |
rel |
str
|
Wanted relation. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
Triple DataFrame with specific relation. |
Examples:
>>> import pandas as pd
>>> rel = pd.DataFrame([("e1","rel1","e2"), ("e3", "rel2", "e1")], columns=["head","relation","tail"])
>>> from embarrassment import select_rel
>>> select_rel(rel, "rel1")
head relation tail
0 e1 rel1 e2
Source code in embarrassment/api.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|