Skip to content

Knowledge graph

KnowledgeGraph

Source code in kgheartbeat\knowledge_graph.py
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 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
 166
 167
 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
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 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
 302
 303
 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
 354
 355
 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
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
class KnowledgeGraph:

    def __init__(self,id):
        self.id = id

    #AVAILABILITY

    def checkEndpointAv(self):
        """Check the SPARQL endpoint availability.

        Returns:
            bool: A boolean that represent the SPARQL endpoint availability (True = Online and False = Offline).
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        try:
            result = q.checkEndPoint(url)
            if isinstance(result,bytes):
                newUrl = utils.checkRedirect(url)
                result = q.checkEndPoint(newUrl)
                if isinstance(result,bytes):
                    available = False
                else:
                    available = True
            else:
                available = True
        except:
            available = False

        return available

    def checkDownload(self):
        """
        Check if the link for download the KG as rdf dump is present and online.

        Returns:
            bool: A boolean that represent the dump link availability (True = Online and False = Offline). 

        """
        resources = aggregator.getOtherResources(self.id)
        resources = utils.insertAvailability(resources)
        available = utils.checkAvailabilityForDownload(resources)

        return available

    def checkInactiveLinks(self):
        """
        Check if there are inactive link associated with the KG.

        Returns:
            bool: A boolean that represent if there are any inactive links associeted with the KG.
        """
        resources = aggregator.getOtherResources(self.id)
        resources = utils.insertAvailability(resources)
        resourcesObj = utils.toObjectResources(resources)
        inactiveLink = False
        for link in resourcesObj:
            if link.status == 'offline':
                inactiveLink = True

        return inactiveLink

    def getURIsDef(self):
        """
        Check the URIs deferenceability. This test is done based on 5000 triples retrieved randomly from the SPARQL endpoint, and for each triple a GET requests is performed.

        Returns:
            float: A float that represent a value which is the ratio between: number of deferenceable URIs and number of total URIs considered.

        """
        url = aggregator.getSPARQLEndpoint(self.id)
        try:
            defCount = 0
            uriCount = 0
            uris = q.getUris(url) #QUERY THAT GET 5000 RANDOM URI FROM THE ENDPOINT 
            for uri in uris:
                if utils.checkURI(uri) == True:
                    uriCount = uriCount + 1
                    try:
                        response = requests.get(uri,headers={"Accept":"application/rdf+xml"},stream=True)
                        if response.status_code == 200:
                            defCount = defCount +1
                    except:
                        continue
            if uriCount > 0:        
                defValue = defCount / uriCount
            else:
                defValue = 'No uri retrieved from the endpoint'
        except: #IF QUERY FAILS (BECUASE SPARQL 1.1 IS NOT SUPPORTED) TRY TO CHECK THE DEFERETIABILITY BY FILTERING THE TRIPLES RECOVERED FOR OTHER CALCULATION (IF THEY ARE BEEN RECOVERED)
            try:
                uriCount = 0
                defCount = 0
                allTriples = q.getAllTriplesSPO(url)
                for i in range(5000):
                    s = allTriples[i].get('s')
                    value = s.get('value')
                    if utils.checkURI(value):
                        uriCount = uriCount + 1
                        try:
                            response = requests.get(value,headers={"Accept":"application/rdf+xml"},stream=True)
                            if response.status_code == 200:
                                defCount = defCount +1
                        except:
                            continue
                if uriCount > 0:
                    defValue = defCount / uriCount
                else:
                    defValue = 'No uri found'
            except:
                defValue = 'Could not process formulated query on indicated endpoint'

        return defValue

    #LICENSING

    def getLicenseMR(self):
        """
        Return the machine-redeable license of the kg, checking on the SPARQL endpopint, in the metadata and in the void file .

        Returns:
            string: A string that represent the machine-redeable license of the KG.
        """
        metadata = aggregator.getDataPackage(self.id)

        licenseM = aggregator.getLicense(metadata) #CHECKING IN THE METADATA
        if isinstance(licenseM,str): 
            return licenseM   #IF LICENSE IS INDICATED IN THE METADATE, RETURN IT

        try:
            licenseQ = q.checkLicenseMR2(aggregator.getSPARQLEndpoint(self.id)) #CHECKING ON THE SPARQL ENDPOINT
            if isinstance(licenseQ,list):
                return licenseQ
        except Exception as e:
            return e

        resources = aggregator.getOtherResources(self.id)
        resources = utils.insertAvailability(resources)
        otResources = utils.toObjectResources(resources)
        urlV = utils.getUrlVoID(otResources)
        if isinstance(urlV,str):  # CHECKING IF VOID FILE IS AVAILABLE
            try:
                voidFile = VoIDAnalyses.parseVoID(urlV)
                void = True
            except:
                try:
                    voidFile = VoIDAnalyses.parseVoIDTtl(urlV)
                    void = True
                except:
                    void = False 
        if void == True:
            licenseV = VoIDAnalyses.getLicense(voidFile)  #GETTING LICENSE FROM THE VOID FILE
            if isinstance(licenseV,str):
                return licenseV

    def getLicenseHR(self):
        """
        Get the human-redeable license, search for a label on the triples in the KG.

        Returns:
            list: A list which contain all the human-redeable license founded in the KG.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        try:
            license = q.checkLicenseHR(url)
        except Exception as e:
            license = e

        return license

    #INTERLINKING

    def getDegreeOfConnection(self):
        """
        Get the degree of connection of kg in the graph constructed with all the kg discoverable.
        At the first call of a function of the interlinking metric a file is created in the directory which contains the graph with all kg discoverable, this is to avoid the construction of the graph every time from scratch.

        Returns: 
            int: An integer that represent the degree of connection.
        """
        graph = utils.checkGraphFile()
        degree = Graph.getDegreeOfConnection(graph,self.id)
        return degree

    def getClusteringCoefficient(self):
        """
        Get the clustering coefficient of kg in the graph constructed with all the kg discoverable.
        At the first call of a function of the interlinking metric a file is created in the directory which contains the graph with all kg discoverable, this is to avoid the construction of the graph every time from scratch.

        Returns:
            float: A float that represent a local clustering coefficient.
        """
        graph = utils.checkGraphFile()
        lcc = Graph.getClusteringCoefficient(graph,self.id)
        lcc = "%.3f"%lcc

        return float(lcc)

    def getCentrality(self):
        """
        Get the centrality of kg in the graph constructed with all the kg discoverable.
        At the first call of a function of the interlinking metric a file is created in the directory which contains the graph with all kg discoverable, this is to avoid the construction of the graph every time from scratch.

        Returns:
            float: A float that is the centrality of the KG.
        """
        graph = utils.checkGraphFile()
        centrality = Graph.getCentrality(graph,self.id)
        centratility = "%.3f"%centrality

        return float(centrality)

    def getSameAsChains(self):
        """
        Return the number of sameAs chains, counting the triples with the predicate equal to owl:sameAs.

        Returns:
            int: A integer that is the number of sameAs chains.
        """
        try:
            url = aggregator.getSPARQLEndpoint(self.id)
            if isinstance(url,str):
                numSameAs = q.getSameAsChains(url)
            else:
                numSameAs = 'SPARQL endpoint absent'
        except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
            numSameAs = 'SPARQL endpoint offline'
        except Exception as e:
            numSameAs = e

        return numSameAs

    def getExternalProvider(self):
        """
        Return a dict with all external provider the key is the id of the KG it is connected to and the value is the number of triples connected, this information is obtained by analyzing the metadata.

        Returns:
            dict: A dict with all external provider.
        """

        extLinks = aggregator.getExternalLinks(self.id)

        return extLinks

    #SECURITY

    def checkAuth(self):
        """
        Check if authentication is required to do SPARQL query on the endpoint.

        Returns:
            bool: A boolean that is True if authentication is required, False otherwise.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                q.checkEndPoint(url)
                return False
            except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed):
                return 'SPARQL endpoint offline'
            except SPARQLExceptions.Unauthorized:
                return True
        else:
            return 'SPARQL endpoint absent'

    def checkHTTPS(self):
        """
        Check if data exchange on the SPARQL endpoint takes place on HTTPS protocol.

        Returns:
            bool: A boolean that is True if HTTPS is used, Flase otherwise.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                isSecure = utils.checkhttps(url)
                if isSecure == True or isinstance(isSecure,list): #IF QUERY ON THE SPARQL ENDPOINT RETURN A RESULT IT IS A LIST, SO URL WITH HTTPS WORKS 
                    return True
                else:
                    return False
            except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
                return 'SPARQL endpoint offline'
            except:
                return False
        else:
            return 'SPARQL endpoint absent'

    #PERFORMANCE

    def getLatency(self):
        """
        Get the latency of the sparql endpoint, is the time passed between the request for a triple and when is returned.
        The value returned is the average latency  of the 5 attempts performed.

        Returns:
            float: A float that is the average latency if SPARQL endpoint is online.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                latency = q.testLatency(url)
                sumL = sum(latency)
                average = sumL/len(latency)
                return average
            except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
                return 'SPARQL endpoint offline'
            except Exception as e:
                return e
        else:
            return 'SPARQL endpoint absent'

    def getThroughput(self):
        """
        Get the throughput of the sparql endpoint, is the number of triples obtained by the endpoint in one second.
        The value returned is the average thrpughput of the 5 attempts performed.

        Returns:
            float: A float that represent the throughput of the SPARQL endpoint.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                tp = utils.getThroughput(url)
                sumTP = sum(tp)
                average = sumTP/len(tp)
                return average
            except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
                return 'SPARQL endpoint offline'
            except Exception as e:
                return e
        else:
            return 'SPARQL endpoint absent'

    #ACCURACY

    def checkEmptyLabel(self):
        """
        Count the number of empty label (if any) in the dataset.

        Returns:
            int: An integer that is the number of empty label is SPQRQL endpoint is online.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                labels = q.getLabel(url)
                emptyL = 0
                for label in labels:
                    if utils.checkURI(label) == False:
                        if label == '':
                            emptyL = emptyL + 1
                return emptyL
            except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
                return 'SPARQL endpoint offline'
            except Exception as e:
                return e
        else:
            return 'SPARQL endpoint absent'

    def checkWhiteSpace(self):
        """
        Count the number of label that have a whitespace at the beginning or at the end.

        Returns:
            int: An integer that is the number of label with whitespace problem if SPARQL endpoint is online.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                wsCount = 0
                labels = q.getLabel(url)
                for label in labels:
                    if utils.checkURI(label) == False:
                        if label != label.strip():
                            wsCount = wsCount + 1
                return wsCount
            except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
                return 'SPARQL endpoint offline'
            except Exception as e:
                return e
        else:
            return 'SPARQL endpoint offline' 

    def checkDatatypeProblem(self):
        """
        Count the number of literal that do not match the data type indicated.

        Returns:
            int: A integer that is the number of literal with datatype problem.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                dataTypeProblem = 0
                triples = q.getAllTriplesSPO(url)
                if isinstance(triples,list):
                    for triple in triples:
                        obj = triple.get('o')
                        value = obj.get('value')
                        if utils.checkURI(value) == False:
                            dataType = obj.get('datatype')
                            if isinstance(dataType,str):
                                regex = utils.getRegex(dataType)
                                if regex is not None:
                                    result = utils.checkString(regex,value)
                                    if result == False:
                                        dataTypeProblem = dataTypeProblem + 1
                    return dataTypeProblem
                else:
                    return "Can't recover triples from the endpoint"
            except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
                return 'SPARQL endpoint offline'
            except Exception as e:
                return e
        else:
            return 'SPARQL endpoint absent'


    def checkFPViolations(self):
        """
        Check for functional properties with inconsistent value, analyzing all triples with predicate owl:FunctionalProperty and checking if there is any violations.

        Returns:
            int: An integer that is the number of triples with functional property violations.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                violationFP = []
                triplesFP = q.getFP(url)
                for triple in triplesFP:
                    s = triple.get('s')
                    subject1 = s.get('value')
                    o = triple.get('o')
                    obj1 = o.get('value')
                    for triple2 in triplesFP:
                        s = triple2.get('s')
                        subject2 = s.get('value')
                        o = triple2.get('o')
                        obj2 = o.get('value')
                        if subject1 == subject2 and obj1 != obj2:
                            violationFP.append(triple)
                return len(violationFP)
            except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
                return 'SPARQL endpoint offline'
            except Exception as e:
                return e
        else:
            return 'SPARQL endpoint absent'

    def checkIFPViolations(self):
        """
        Check for invalid usage of inverse-functional properties, analyzing all triples with predicate owl:InverseFunctionalProperty and checking if there is any violations. 

        Returns:
            int: An integer that is the number of triples with inverse-functional properties violations.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                violationIFP = []
                triplesIFP = q.getIFP(url)
                for triple in triplesIFP:
                    s = triple.get('s')
                    subject1 = s.get('value')
                    o = triple.get('o')
                    obj1 = o.get('value')
                    for triple2 in triplesIFP:
                        s = triple2.get('s')
                        subject2 = s.get('value')
                        o = triple2.get('o')
                        obj2 = o.get('value')
                        if obj1 == obj2 and subject1 != subject2:
                            violationIFP.append(triple)
                return len(violationIFP)
            except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
                return 'SPARQL endpoint offline'
            except Exception as e:
                return e
        else:
            return 'SPARQL endpoint absent'

    #CONSISTENCY    

    def getDisjointValue(self):
        """
        Get the disjoint value. It is calculated by counting the number of triples with predicate owl:disjointWith and then making the ratio between number of triples with that predicate and number of entities.

        Returns:
            float: A float that represent the disjoint value if triples and entity is recovered correctly form SPARQL endpoint.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                numDisjoint = q.getDisjoint(url)
                numEntities = q.getNumEntities(url)
                if not isinstance(numEntities,int):
                    regex = []
                    regex = q.checkUriRegex(url)
                    pattern = q.checkUriPattern(url)
                    for p in pattern:
                        newRegex = utils.trasforrmToRegex(p)
                        regex.append(newRegex)
                    if len(regex) > 0:
                        numEntities = 0
                        for r  in regex:
                            numEntities = numEntities + q.getNumEntitiesRegex(url,r)
                if isinstance(numDisjoint,int):
                    try:
                        numEntities = int(numEntities)
                        if numEntities > 0:
                            disjointValue = numDisjoint/numEntities
                            disjointValue = "%.3f"%disjointValue
                            disjointValue = float(disjointValue)
                        else:
                            disjointValue = 'insufficient data'
                    except:
                        disjointValue = 'insufficient data'   

                    return disjointValue     
            except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
                return 'SPARQL endpoint offline'   
            except Exception as e:
                return e
        else:
            return 'SPARQL endpoint absent'

    def getUndefinedClass(self):
        """
        Get the classes used without declaration.

        Returns:
            list: A list that contains undefined classes
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                allTriples = q.getAllTriplesSPO(url)
                allType = q.getAllType(url)
                toSearch = []
                found = False
                for i in range(len(allTriples)):
                    s = allTriples[i].get('s')
                    s = s.get('value')
                    allType.sort()
                    r = utils.binarySearch(allType,0,len(allType)-1,s)
                    if r != -1:
                        found = True
                        break
                    if found == False:
                        result = utils.checkURI(s)
                        if result == True:
                            toSearch.append(s)
                    found = False
                undClasses = LOVAPI.searchTermsList(toSearch)
            except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
                return 'SPARQL endpoint offline'
            except Exception as e:
                return e

            return undClasses
        else:
            return 'SPARQL endpoint absent'

    def getUndefinedProp(self):
        """
        Get the properties used without declaration.

        Returns:
            list: A list that contains a list of undefined properties. 
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                uriListP = q.getAllPredicate(url)
                properties = q.getAllProperty(url)
                toSearch = []
                found = False
                for i in range(len(uriListP)):
                    p = uriListP[i]
                    properties.sort()
                    r = utils.binarySearch(properties,0,len(properties)-1,p)
                    if r != -1:
                        found = True
                        break
                    if found == False:
                        result = utils.checkURI(p)
                        if result == True:
                            toSearch.append(p)
                    found = False
                undProperties = LOVAPI.searchTermsList(toSearch)
            except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
                undProperties = 'SPARQL endpoint offline'
            except :
                undProperties = 'Could not process formulated query on indicated endpoint'

            return undProperties

        else:
            return 'SPARQL endpoint absent'

    def checkDeprecatedClassesProp(self):
        """
        Check if deprecated classes and properties are used in the KG.

        Returns:
            list: A list that contains  deprecated classes and properties used in the KG.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                deprecated = q.getDeprecated(url)
            except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
                return 'SPARQL endpoint offline'
            except Exception as e:
                deprecated = e

            return deprecated
        else:
            return 'SPARQL endpoint absent'            

    def checkOntologyHijacking(self):
        """
        Check for the ontology hijacking problem, if the SPARQL endpoint is online.
        This problem is present if there are a re-definition of classes or properties considered standard for LOD.

        Returns:
            bool: A boolean that is True if there is a Ontology Hijacking problem, False otherwise.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                allType = q.getAllType(url)
                triplesOH = False
                if isinstance(allType,list):
                    triplesOH = LOVAPI.searchTermsList(allType)
                    if len(triplesOH) > 0:
                        hijacking = True
                    else:
                        hijacking = False
                else:
                    hijacking = 'Impossible to retrieve the terms defined in the dataset'
            except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
                hijacking = 'SPARQL endpoint offline'
            except:
                hijacking = 'Could not process formulated query on indicated endpoint'

            return hijacking
        else:
            return 'SPARQL endpoint absent'

    def checkMisplacedClasses(self):
        """
        Check if the classes are used incorrectly, classes are used in the position of the predicate.

        Returns:
            list: A list of misplaced classes.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                misplacedClass = []
                properties = q.getAllProperty(url)
                allTriples = q.getAllTriplesSPO(url)
                found = False
                if isinstance(allTriples,list) and isinstance(properties,list):
                    properties.sort()
                    for i in range(len(allTriples)):
                        o = allTriples[i].get('o')
                        valueO = o.get('value')
                        s = allTriples[i].get('s')
                        valueS = s.get('value')
                        result = utils.checkURI(valueS)
                        if result == True:
                            r = utils.binarySearch(properties,0,len(properties)-1,valueS)
                            if r != -1:
                                found = True
                        resultO = utils.checkURI(valueO)
                        if found == False and resultO == True:
                            r2 = utils.binarySearch(properties,0,len(properties)-1,valueO)
                            if r2 != -1:
                                found = True
                        if found == True:
                            misplacedClass.append(valueS)
                            found = False
                else:
                    misplacedClass = 'insufficient data'
            except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
                misplacedClass = 'SPARQL endpoint offline'
            except TimeoutError:
                misplacedClass = 'Timeout'
            except:
                misplacedClass = 'Could not process formulated query on indicated endpoint'

            return misplacedClass
        else:
            return 'SPARQL endpoint absent'

    def checkMisplacedProperty(self):
        """
        Check if the properties are used incorrectly, properties are used in the position of the subject.

        Returns:
            list: A list of properties with misplaced propery problem.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                misplacedProperty = []
                classes = q.getAllClasses(url)
                uriListP = q.getAllPredicate(url)
                if isinstance(uriListP,list) and isinstance(classes,list):
                    for i in range(len(uriListP)):
                        p = uriListP[i]
                        result = utils.checkURI(p)
                        if result == True:
                            classes.sort()
                            r = utils.binarySearch(classes,0,len(classes)-1,p)
                            if r != -1:
                                misplacedProperty.append(p)
                else:
                    misplacedProperty = 'insufficient data'
            except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
                misplacedProperty =  'SPARQL endpoint offline'
            except Exception as e:
                misplacedProperty = e

            return misplacedProperty
        else:
            return 'SPARQL endpoint absent'

    #CONCISENESS

    def getIntensionalConc(self):
        """
        Get the intensional conciseness value, it is calculated by the following formula: 1.0 - #duplicated properties (calculated with Bloom filter algorithm)/#triples in the dataset.

        Returns:
            float: A float that is the intensional conciseness value.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                allProperty = q.getAllPropertySP(url)
                triplePropList = []
                duplicateP = []
                if isinstance(allProperty,list):
                    if len(allProperty) > 0:
                        for i in range(len(allProperty)):
                            s = allProperty[i].get('s')
                            p = allProperty[i].get('p')
                            subP = s.get('value')
                            predP = p.get('value')
                            tripleProp = subP + predP
                            triplePropList.append(tripleProp)
                        bloomF2 = BloomFilter(len(triplePropList),0.05)
                        for j in range(len(triplePropList)):
                            found = bloomF2.check(triplePropList[j])
                            if found == False:
                                bloomF2.add(triplePropList[j])
                            elif found == True:
                                duplicateP.append(triplePropList[j])
                        if len(allProperty) > 0:
                            intC = 1.0 - (len(duplicateP)/len(allProperty))
                            intC = "%.3f"%intC
                            intC = float(intC)
                        else:
                            intC = 'insufficient data'
                    else:
                        intC = '0 properties retrieved from the endpoint'
                else:
                    intC = 'insufficient data'
            except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
                intC = 'SPARQL endpoint offline'
            except:
                intC = 'Could not process formulated query on indicated endpoint'

            return intC
        else:
            return 'SPARQL endpoint absent'

    def getExtensionaConc(self):
        """
        Get the extensional conciseness value, it is calculated by the following formula: 1.0 - #duplicated triples (calculated with Bloom filter algorithm) / #triples in the dataset.

        Returns:
            float: A float that is the extensional conciseness value.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                allTriples = q.getAllTriplesSPO(url)
                tripleList = []
                duplicate = []
                if isinstance(allTriples,list):
                    if len(allTriples)> 0:    
                        for i in range(len(allTriples)):
                            s = allTriples[i].get('s')
                            p = allTriples[i].get('p')
                            o = allTriples[i].get('o')
                            subject = s.get('value')
                            predicate = p.get('value')
                            object = o.get('value')
                            triple = subject + predicate + object
                            tripleList.append(triple)
                        bloomF = BloomFilter(len(tripleList),0.05)
                        print("Size of bit array:{}".format(bloomF.size))
                        print("False positive Probability:{}".format(bloomF.fp_prob))
                        print("Number of hash functions:{}".format(bloomF.hash_count))
                        for i in range(len(tripleList)):
                            found = bloomF.check(tripleList[i])
                            if found == False:
                                bloomF.add(tripleList[i])
                            elif found == True:
                                duplicate.append(tripleList[i])

                        if len(allTriples) > 0:
                            exC = 1.0 - (len(duplicate)/len(allTriples)) # From: Evaluating the Quality of the LOD Cloud: An Empirical Investigation (Ruben Verborgh)
                            exC = "%.3f"%exC
                            exC = float(exC)
                        else:
                            exC = 'insufficient data'
                    else:
                        exC = '0 triples retrieved from the endpoint'
                else:
                    exC = 'insufficient data'
            except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
                exC = 'SPARQL endpoint offline'
            except:
                exC = 'Could not process formulated query on indicated endpoint'

            return exC
        else:
            return 'SPARQL endpoint absent'

    #REPUTATION
    def getPageRank(self):
        """
        Get the pagerank of KG based on the graph constructed with all the kg discoverable.

        Returns:
            float: A float that represent the pagerank value.
        """
        graph = utils.checkGraphFile()
        pageRank = Graph.getPageRank(graph,self.id)
        pageRank = "%.4f"%pageRank

        return float(pageRank)

    #BELIEVABILITY
    def getName(self):
        """
        Get the title of the KG by analyzing the metadata.

        Returns:
            string: A string that contains the title of the KG.
        """
        metadata = aggregator.getDataPackage(self.id)
        title = aggregator.getNameKG(metadata)

        return title

    def getDescription(self):
        """
        Get the description of the KG by analyzing the metadata.

        Returns:
            string: A string that contains a description of the KG.  
        """
        metadata = aggregator.getDataPackage(self.id)
        description = aggregator.getDescription(metadata)

        return description

    def getUri(self):
        """
        Get the URI of the KG by analyzing the metadata.

        Returns:
            string: A tring that is the URI of the KG.
        """
        metadata = aggregator.getDataPackage(self.id)
        sources = aggregator.getSource(metadata)
        url = sources.get('web','Absent')

        return url

    def calculateTrustValue(self):
        """
        Calculate the trust value of the KG. It is a value between -1 and 1, -1 when all believability data is absent, value beetween 0 and 1 based on how many values are present.

        Returns:
            int: A integer that is the trust value of the KG.
        """
        metadata = aggregator.getDataPackage(self.id)
        title = aggregator.getNameKG(metadata)
        description = aggregator.getDescription(metadata)
        sources = aggregator.getSource(metadata)
        url = sources.get('web','Absent')

        #CHECK IF THE KG IS IN A LIST OF RELIABLE PROVIDERS
        try:
            providers = ['wikipedia','government','bioportal','bio2RDF','academic']
            keywords = aggregator.getKeywords(self.id)
            if any(x in keywords for x in providers):
                believable = True
            else:
                believable = False
        except:
            believable = 'absent'
        valueN = 0
        valueD = 0
        valueUrl = 0
        valuePr = 0
        if isinstance(title,str):
            if title != '' and title != 'Absent' and title != 'absent':
                valueN = 1
        if isinstance(description,str):
            if description != '' and description != False and description != 'Absent':
                valueD = 1
        if isinstance(url,str):
            if url != '' and url !='Absent' and url != 'absent':
                valueUrl = 1
        if believable == True:
            valuePr = 1

        if valueN == 0 and valueD == 0 and valueUrl == 0 and valuePr == 0:
            trustValue = -1

        trustValue = (valueN+valueD+valueUrl+valuePr)/4

        return trustValue

    #VERIFIABILITY

    def getVocabularies(self):
        """
        Get all the vocabularies used in the KG. This information is retrived from the SPARQL endpoint or VOID file.

        Returns:
            list: A list that contains all the vocabularies used in the KG.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        voidFile = utils.checkVoidFile(self.id)
        if isinstance(url,str):
            try:
                vocabularies = q.getVocabularies(url)
            except:
                vocabularies = 'SPARQL endpoint offline'
                if not isinstance(voidFile,bool):  #IF SPARQL ENDPOINT IS OFFLINE TRY TO GET THE VOCABULARIES FROM VOID FILE
                    vocabularies = VoIDAnalyses.getVocabularies(voidFile)
        elif not isinstance(voidFile,bool): #IF SPARQL ENDPOINT IS ABSENT TRY TO GET THE VOCABULARIES FROM VOID FILE
            vocabularies = VoIDAnalyses.getVocabularies(voidFile)
        else:
            vocabularies = 'Impossible to retrieve vocabularies from SPARQL endopoint or VOID file'

        return vocabularies

    def getAuthors(self):
        """
        Get all KG authors. This information is retrived from the SPARQL endpoint or VOID file.

        Returns:
            list: A list that contains all the authors of the KG.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        voidFile = utils.checkVoidFile(self.id)
        if isinstance(url,str):
            try:
                authors = q.getCreator(url)
            except:
                authors = 'SPARQL endpoint offline'
                if not isinstance(voidFile,bool):
                    authors = VoIDAnalyses.getCreators(voidFile)
        elif not isinstance(voidFile,bool):
            authors = VoIDAnalyses.getCreators(voidFile)
        else:
            authors = 'Impossible to retrieve vocabularies from SPARQL endopoint or VOID file'

        return authors

    def getPublishers(self):
        """
        Get all the KG pubilshers. This information is retrived from the SPARQL endpoint or VOID file.

        Returns:
            list: A list that contains the publishers of the KG.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        voidFile = utils.checkVoidFile(self.id)
        if isinstance(url,str):
            try:
                publishers = q.getPublisher(url)
            except:
                publishers = 'SPARQL endpoint offline'
                if not isinstance(voidFile,bool):
                    publishers = VoIDAnalyses.getPublishers(voidFile)
        elif not isinstance(voidFile,bool):
            publishers = VoIDAnalyses.getPublishers(voidFile)
        else:
            publishers = 'Impossible to retrieve vocabularies from SPARQL endopoint or VOID file'

        return publishers

    def getContributors(self):
        """
        Get all the KG contributors. This information is retrived from the SPARQL endpoint or VOID file.

        Returns:
            list: A list that contains all the contributors to the KG.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        voidFile = utils.checkVoidFile(self.id)
        if isinstance(url,str):
            try:
                contributors = q.getContributors(url)
            except:
                contributors = 'SPARQL endpoint offline'
                if not isinstance(voidFile,bool):
                    contributors = VoIDAnalyses.getContributors(voidFile)
        elif not isinstance(voidFile,bool):
            contributors = VoIDAnalyses.getContributors(voidFile)
        else:
            contributors = 'Impossible to retrieve vocabularies from SPARQL endopoint or VOID file'

        return contributors

    def getSources(self):
        """
        Get the KG sources. This return a Sources object that contains three field: web, email, name.

        Returns:
            Sources object: A Sources object that contain information about web address, email, name authors or maintainer.
        """
        metadata = aggregator.getDataPackage(self.id)
        sources = aggregator.getSource(metadata)
        if sources == False:
            sourcesObj = Sources('Absent','Absent','Absent')
        else:
            sourcesObj = Sources(sources.get('web','Absent'),sources.get('name','Absent'),sources.get('email','Absent'))

        return sourcesObj  #use sourcesKG() to print information about sources

    def checkSign(self):
        """
        Check if the KG is signed.

        Returns:
            bool: A boolean that is True if is signed, False otherwise.l
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                sign = q.getSign(url)
                if isinstance(sign,int):
                    if sign > 0:
                        signed = True
                    else:
                        signed = False
                else:
                    signed = False
            except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
                signed = 'SPARQL endpoint offline'
            except :
                signed = 'Could not process formulated query on indicated endpoint'
        else:
            signed = 'SPARQL endpoint absent'

        return signed

    #CURRENCY

    def getCreationDate(self):
        """
        Get the KG creation date. This information is retrived from the SPARQL endpoint or VOID file. False is returned if SPARQL endpoint is offline

        Returns:
            string: A string that is the KG creation date  
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        voidFile = utils.checkVoidFile(self.id)
        if isinstance(url,str):
            try:
                creationD = q.getCreationDateMin(url)
            except:
                creationD = False
                try:
                    creationD = q.getCreationDate(url)
                except:
                    creationD = False
                if not isinstance(voidFile,bool) and not isinstance(creationD,str):
                    creationD = VoIDAnalyses.getCreationDate(voidFile)
        elif not isinstance(voidFile,bool):
            creationD = VoIDAnalyses.getCreationDate(voidFile)
        else:
            creationD = 'SPARQL endpoint and VoID absent'

        return creationD

    def getModificationDate(self):
        """
        Get the KG modification date. This information is retrived from SPARQL endpoint or VOID file. False is returned if SPARQL endpoint is offline.

        Returns:
            string: A string that contains a KG modification date.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        voidFile = utils.checkVoidFile(self.id)
        if isinstance(url,str):
            try:
                modificationD = q.getModificationDateMax(url)
            except:
                modificationD = False
                try:
                    modificationD = q.getModificationDate(url)
                except:
                    modificationD = False
                if not isinstance(voidFile,bool) and not isinstance(modificationD,str):
                    modificationD = VoIDAnalyses.getCreationDate(voidFile)
        elif not isinstance(voidFile,bool):
            modificationD = VoIDAnalyses.getCreationDate(voidFile)
        else:
            modificationD = 'SPARQL endpoint and VoID absent'

        return modificationD

    def getPercentageUpData(self,modificationDate):
        """
        Get the percentage of updated data. The percentage is calcualted based on the modificationDate given as a parameter.

        Returns:
            string: A percentage of updated data.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                numTriplesUp = q.getNumUpdatedData(url,modificationDate)
            except:
                numTriplesUp = 'SPARQL endpoint offline'
        else:
            numTriplesUp = 'SPARQL endpoint absent'

        return numTriplesUp

    def getLastUp(self):
        """
        Get the elapsed time since the last modification (in days).

        Returns:
            string: A string that represent the days that have passed since the last modification.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        voidFile = utils.checkVoidFile(self.id)
        if isinstance(url,str):
            try:
                modificationD = q.getModificationDateMax(url)
            except:
                modificationD = False
                try:
                    modificationD = q.getModificationDate(url)
                except:
                    modificationD = False
                if not isinstance(voidFile,bool) and not isinstance(modificationD,str):
                    modificationD = VoIDAnalyses.getCreationDate(voidFile)
        elif not isinstance(voidFile,bool):
            modificationD = VoIDAnalyses.getCreationDate(voidFile)
        else:
            modificationD = 'SPARQL endpoint and VoID absent'
        try:
            today = datetime.date.today()
            todayFormatted = today.strftime("%Y-%m-%d")
            todayDate =  datetime.datetime.strptime(todayFormatted, "%Y-%m-%d").date()
            modificationD = datetime.datetime.strptime(modificationD, "%Y-%m-%d").date()
            delta = (todayDate - modificationD).days
        except:
            delta = 'Insufficient data'


        return delta

    #VOLATILITY

    def getFrequencyUp(self):
        """
        Get the KG update frequency. This information is retrived from SPARQL endpoint or VOID file.

        Returns:
            string: A string that contains the KG update frequency.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        voidFile = utils.checkVoidFile(self.id)
        if isinstance(url,str):
            try:
                frequency = q.getFrequency(url)
            except:
                frequency = 'SPARQL endpoint offline'
                if not isinstance(voidFile,bool):
                    frequency = VoIDAnalyses.getFrequency(voidFile)
        elif not isinstance(voidFile,bool):
            frequency = VoIDAnalyses.getFrequency(voidFile)
        else:
            frequency = 'SPARQL endpoint and VoID file absent'

        return frequency

    #COMPLETENESS

    def getInterlinkingComp(self):
        """
        Calcuate the interlinking completeness. It is calculated by the ratio between the number of linked triples and number of all triples in the dataset.

        Returns:
            int: An integer that is the interlinking completeness of the KG.
        """
        externalLinks = aggregator.getExternalLinks(self.id)
        exLinksObj = utils.toObjectExternalLinks(externalLinks)
        triplesL = 0
        for i in range(len(exLinksObj)): #COUNTING THE NUMBER OF TRIPLES CROSS EXTERNAL LINK LIST IN THE METADATA
            link = exLinksObj[i]
            value = link.value
            value = str(link.value)
            value = re.sub("[^\d\.]", "",value) #CHECK IF THE VALUE IS A NUMBER
            value = int(value)
            triplesL = triplesL + value
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                triples = q.getNumTripleQuery(url) #COUNT THE NUMBER OF TRIPLES WITH A SPARQL QUERY
            except:   #IF SPARQL ENDPOINT IS OFFLINE, COUNT THE TRIPLES BY ANALYZING THE METADATA
                triples = 'SPARQL endpoint offline'
                metadata = aggregator.getDataPackage(self.id)
                triples = aggregator.getTriples(metadata)
        else:
            triples = 'SPARQL endpoint and VoID file absent'

        try:
            triplesL = int(triplesL)
            triples = int(triples)
            if triples > 0:
                iCompl = (triplesL/triples)
                iCompl = "%.2f"%iCompl
                iCompl = float(iCompl)
            else:
                iCompl = 'Insufficient data'
        except:
            iCompl = 'Insufficient data'

        return iCompl

    #AMOUNT OF DATA

    def getNumTriples(self):
        """
        Get the number of triples in the KG. This information can be obtained by SPARQL endpoint or analyzing the metadata of the dataset.

        Returns:
            int: An integer that is the number of triples.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        metadata = aggregator.getDataPackage(self.id)
        if isinstance(url,str):
            try:
                triples = q.getNumTripleQuery(url)
            except:
                triples = 'SPARQL endpoint offline'
                triples = aggregator.getTriples(metadata)
        else:
            triples = aggregator.getTriples(metadata)

        return triples

    def getNumEntities(self):
        """
        Count the number of entities in the dataset. This information can be obtained by a SPARQL endpoint or analyzing the VoID file.

        Returns:
            int: An integer that is the number of entities in the KG.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        voidFile = utils.checkVoidFile(self.id)
        if isinstance(url,str):
            try:
                entities = q.getNumEntities(url)
                try:
                    entities = int(entities)
                    return entities
                except:  #IF WITH THE FIRST QUERY WE DON'T GET THE RESULT, WE TRY TO COUNT THE NUMBER OF ENTITIES BY COUNTING THE NUMBER OF TRIPLES THAT MATH WITH THEKG URI REGEX
                    #GET THE REGEX OF THE URLs USED
                    regex = []
                    try:
                        regex = q.checkUriRegex(url)
                    except:
                        regex = 'Could not process formulated query on indicated enpdoint'

                    #CHECK IF IS INDICATED A URI SPACE INSTEAD OF A REGEX AND WE TRAFORM IT TO REGEX
                    try:    
                        pattern = q.checkUriPattern(url)  
                        if isinstance(pattern,list):
                            for i in range(len(pattern)): 
                                newRegex = utils.trasforrmToRegex(pattern[i])
                                regex.append(newRegex)
                    except:
                        pattern = 'Could not process formulated query on indicated enpdoint'

                    #NOW COUNT THE ENITITIES USING THE REGEX
                    try:
                        if len(regex) > 0:
                            entities = 0
                            for i in range(len(regex)):
                                entities = entities + q.getNumEntitiesRegex(url,regex[i])
                        else:
                            entities = 'insufficient data'
                    except Exception as e:
                        entities = e

                    return entities
            except:
                if not isinstance(voidFile,bool):
                    entities = VoIDAnalyses.getNumEntities(voidFile)
                    return entities
        elif not isinstance(voidFile,bool):
            entities = VoIDAnalyses.getNumEntities(voidFile)
            return entities
        else:
            return 'SPARQL endpoint and VoID file absent'

    def getNumProperty(self):
        """
        Get the number of property in the KG. This information is retrived by executing a query on the SPARQL endpoint.

        Returns:
            int: An integer that is the number of properties in the KG.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                numProperty = q.numberOfProperty(url)
            except:
                numProperty = 'SPARQL endpoint offline'
        else:
            numProperty = 'SPARQL endpoint absent'

        return numProperty

    #REPRESENTATIONAL-CONCISENESS

    def getUriLenghtSub(self):
        """
        Get the uri's length in the subject position. The returned value is a list in which the values are respectively min-max-average-standard deviation.

        Returns:
            list: A list that contains all the URI in the KG.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                lengthtList = []
                triples = q.getAllTriplesSPO(url)
                for triple in triples:
                    s = triple.get('s')
                    uri = s.get('value')
                    if utils.checkURI(uri) == True:
                        lengthtList.append(len(uri))
                sumLenghts = sum(lengthtList)
                avLenghts = sumLenghts/len(lengthtList) 
                avLenghts = str(avLenghts)
                avLenghts = avLenghts.replace('.',',')
                standardDeviationL = numpy.std(lengthtList)
                standardDeviationL = str(standardDeviationL)
                standardDeviationL = standardDeviationL.replace('.',',')
                minLenghtS = min(lengthtList)
                maxLenghtS = max(lengthtList)
                length = [minLenghtS,maxLenghtS,avLenghts,standardDeviationL]
            except:
                length = 'SPARQL endpoint offline'
        else:
            length = 'SPARQL endpoint absent'

        return length

    def getUriLenghtObj(self):
        """
        Get the uri's length in the object position. The returned value is a list in which the values are respectively min-max-average-standard deviation.

        Returns:
            list: A list that contains all the URI in the object position
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                uriListO = q.getAllObject(url)
                lengthtList = []
                for triple in uriListO:
                    if utils.checkURI(triple) == True:
                        lengthtList.append(len(triple))
                sumLenghts = sum(lengthtList)
                avLenghts = sumLenghts/len(lengthtList) 
                avLenghts = str(avLenghts)
                avLenghts = avLenghts.replace('.',',')
                standardDeviationL = numpy.std(lengthtList)
                standardDeviationL = str(standardDeviationL)
                standardDeviationL = standardDeviationL.replace('.',',')
                minLenghtS = min(lengthtList)
                maxLenghtS = max(lengthtList)
                length = [minLenghtS,maxLenghtS,avLenghts,standardDeviationL]
            except:
                length = 'SPARQL endpoint offline'
        else:
            length = 'SPARQL endpoint absent'

        return length

    def getUriLenghtPr(self):
        """
        Get the uri's length in the predicate position. The returned value is a list in which the values are respectively min-max-average-standard deviation.

        Returns:
            list: A list that contains URIs in the predicate position.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                uriListP = q.getAllPredicate(url)
                lengthtList = []
                for triple in uriListP:
                    if utils.checkURI(triple) == True:
                        lengthtList.append(len(triple))
                sumLenghts = sum(lengthtList)
                avLenghts = sumLenghts/len(lengthtList) 
                avLenghts = str(avLenghts)
                avLenghts = avLenghts.replace('.',',')
                standardDeviationL = numpy.std(lengthtList)
                standardDeviationL = str(standardDeviationL)
                standardDeviationL = standardDeviationL.replace('.',',')
                minLenghtS = min(lengthtList)
                maxLenghtS = max(lengthtList)
                length = [minLenghtS,maxLenghtS,avLenghts,standardDeviationL]
            except:
                length = 'SPARQL endpoint offline'
        else:
            length = 'SPARQL endpoint absent'

        return length

    def checkRDFStr(self):
        """
        Check if RDF data structures is used in the KG. 

        Returns:
            bool: A boolean that is True if are used, False otherwise.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                rdf = q.checkRDFDataStructures(url)
            except:
                rdf = 'SPARQL endpoint offline'
        else:
            rdf = 'SPARQL endpoint absent'

        return rdf

    #REPRESENTATIONAL-CONSISTENCY

    def checkReuseTerms(self):
        """
        Check usage of existing terms. This check is done using the Linked Open Vocabulary, a KG that contains vocabulary and terms standard for Linked Open Data.

        Returns:
            bool: A boolean that is True if no new terms are defined, False otherwise.

        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                objList = []
                triplesO = q.getAllTypeO(url)
                for term in triplesO:
                    objList.append(term)
                newTermsD = LOVAPI.searchTermsList(objList)
                if len(newTermsD) > 0:
                    return False
                else:
                    return True
            except:
                return 'SPARQL endpoint offline'
        else:
            return 'SPARQL endpoint absent'

    def checkReuseVocabs(self):
        """
        Check usage of existing vocabularies. This check is done using the Linked Open Vocabulary, a KG that contains vocabularies and terms standard for Linked Open Data.

        Returns:
            bool: A boolean that is True if no new vocabularies are defined, False otherwise.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                newVocab = []
                vocabs = q.getVocabularies(url)
                if isinstance(vocabs,list):
                    for vocab in vocabs:
                        result = LOVAPI.findVocabulary(vocab)
                        if result == False:
                            newVocab.append(vocab)
                    if len(newVocab) > 0:
                        return False
                    else:
                        return True
                else:
                    return 'Impossible to retrieve KG vocabularies'
            except:
                return 'SPARQL endpoint offline'
        else:
            return 'SPARQL endpoint absent'

    #UNDERSTENDABILITY

    def getNumLabels(self):
        """
        Count the number of label on the triples in the KG. This count is done by using a query on the SPARQL endpoint.

        Returns:
            int: An integer that is the number of label in the KG.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                numLabel = q.getNumLabel(url)
            except:
                numLabel = 'SPARQL endpoint offline'
        else:
            numLabel = 'SPARQL endpoint absent'

        return numLabel

    def getRegex(self):
        """
        Return the uri regex of the KG. This check id done by using a query on the SPARQL endpoin or by analyzing the VoID file if available.

        Returns:
            list: A list with the URI regex
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        voidFile = utils.checkVoidFile(self.id)
        if isinstance(url,str):
            regex = []
            try:
                regex = q.checkUriRegex(url)
            except Exception as e:
                regex = 'SPARQL endpoint offline'
                if not isinstance(voidFile,bool):
                    regex = VoIDAnalyses.getUriRegex(voidFile) 
            #CHECK IF IS INDICATED A URI SPACE INSTEAD OF A REGEX AND WE TRAFORM IT TO REGEX
            try:    
                pattern = q.checkUriPattern(url)  
                if isinstance(pattern,list):
                    for i in range(len(pattern)): 
                        newRegex = utils.trasforrmToRegex(pattern[i])
                        regex.append(newRegex)
            except:
                pattern = 'SPARQL endpoint offline'
        elif not isinstance(voidFile,bool):
            regex = VoIDAnalyses.getUriRegex(voidFile)
        else:
            regex = 'SPARQL endpint absent'

        return regex

    def checkExample(self):
        """
        Check if query examples are provided with the KG. This information is obtained by analyzing the KG metadata, in particular, the field other resources.

        Returns:
            bool: A boolean that is True if there are any query examples , False otherwise.
        """
        resources = aggregator.getOtherResources(self.id)
        resources = utils.insertAvailability(resources)
        otResources = utils.toObjectResources(resources)
        example = False
        for j in range(len(otResources)):
            if isinstance(otResources[j].format,str):
                if 'example' in otResources[j].format:
                    example = True
            if isinstance(otResources[j].title,str):
                if 'example' in otResources[j].title:
                    example = True

        return example

    #INTERPRETABILITY

    def getNumbBN(self):
        """
        Get the blank node number. This is obtained by querying the SPARQL endpoint.

        Returns:    
            int: An integer that represent the number of blank node in the KG.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                numBlankN = q.numBlankNode(url)
            except:
                numBlankN = 'SPARQL endpoint offline'
        else:
            numBlankN = 'SPARQL endpoint absent'

        return numBlankN

    #VERSATILIY

    def getSerializationFormat(self):
        """
        Get the KG serialization formats. This information is retrived by executing a query on the SPARQL endpoint or from VoID file if available.

        Returns:
            list: A list that contains all the serialization formats supported by the KG.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        voidFile = utils.checkVoidFile(self.id)
        if isinstance(url,str):
            try:
                formats = q.checkSerialisationFormat(url)
            except:
                formats = 'SPARQL endpoint offline'
                if not isinstance(voidFile,bool):
                    formats = VoIDAnalyses.getSerializationFormats(voidFile)
        elif not isinstance(voidFile,bool):
            formats = VoIDAnalyses.getSerializationFormats(voidFile)
        else:
            formats = 'SPARQL endpoint and VoID file absent'

        return formats

    def getLanguages(self):
        """
        Get the languages supported by the KG. This information is retrieved by querying the SPARQL endpoint.

        Returns:
            list: A list with all the languages supprted by the KG.
        """
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            try:
                languages = q.getLangugeSupported(url)
            except:
                languages = 'SPARQL endpoint offline'
        else:
            languages = 'SPARQL endpoint absent'

        return languages

    def getAccessAtKG(self):
        """
        Get the ways in which you can access the KG. This information is retrived by analyzing the metadata and/or querying the SPARQL endpoint.

        Returns:
            list: A list with all the links to access to the KG.
        """
        links = []
        url = aggregator.getSPARQLEndpoint(self.id)
        voidFile = utils.checkVoidFile(self.id)
        resources = aggregator.getOtherResources(self.id)
        resources = utils.insertAvailability(resources)
        links = links + utils.getLinkDownload(resources)
        if isinstance(url,str):
            links.append(url)
            try:
                urlList = q.checkDataDump(url)
                if isinstance(urlList,list):
                    activeUrl = utils.getActiveDumps(urlList)
                    links = links + activeUrl
            except:
                pass
        elif not isinstance(voidFile,bool):
            links = links + VoIDAnalyses.getDataDump(voidFile)

        links = list(dict.fromkeys(links)) #REMOVE DUPLICATES IN THE LIST

        return links

calculateTrustValue()

Calculate the trust value of the KG. It is a value between -1 and 1, -1 when all believability data is absent, value beetween 0 and 1 based on how many values are present.

Returns:

Name Type Description
int

A integer that is the trust value of the KG.

Source code in kgheartbeat\knowledge_graph.py
def calculateTrustValue(self):
    """
    Calculate the trust value of the KG. It is a value between -1 and 1, -1 when all believability data is absent, value beetween 0 and 1 based on how many values are present.

    Returns:
        int: A integer that is the trust value of the KG.
    """
    metadata = aggregator.getDataPackage(self.id)
    title = aggregator.getNameKG(metadata)
    description = aggregator.getDescription(metadata)
    sources = aggregator.getSource(metadata)
    url = sources.get('web','Absent')

    #CHECK IF THE KG IS IN A LIST OF RELIABLE PROVIDERS
    try:
        providers = ['wikipedia','government','bioportal','bio2RDF','academic']
        keywords = aggregator.getKeywords(self.id)
        if any(x in keywords for x in providers):
            believable = True
        else:
            believable = False
    except:
        believable = 'absent'
    valueN = 0
    valueD = 0
    valueUrl = 0
    valuePr = 0
    if isinstance(title,str):
        if title != '' and title != 'Absent' and title != 'absent':
            valueN = 1
    if isinstance(description,str):
        if description != '' and description != False and description != 'Absent':
            valueD = 1
    if isinstance(url,str):
        if url != '' and url !='Absent' and url != 'absent':
            valueUrl = 1
    if believable == True:
        valuePr = 1

    if valueN == 0 and valueD == 0 and valueUrl == 0 and valuePr == 0:
        trustValue = -1

    trustValue = (valueN+valueD+valueUrl+valuePr)/4

    return trustValue

checkAuth()

Check if authentication is required to do SPARQL query on the endpoint.

Returns:

Name Type Description
bool

A boolean that is True if authentication is required, False otherwise.

Source code in kgheartbeat\knowledge_graph.py
def checkAuth(self):
    """
    Check if authentication is required to do SPARQL query on the endpoint.

    Returns:
        bool: A boolean that is True if authentication is required, False otherwise.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            q.checkEndPoint(url)
            return False
        except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed):
            return 'SPARQL endpoint offline'
        except SPARQLExceptions.Unauthorized:
            return True
    else:
        return 'SPARQL endpoint absent'

checkDatatypeProblem()

Count the number of literal that do not match the data type indicated.

Returns:

Name Type Description
int

A integer that is the number of literal with datatype problem.

Source code in kgheartbeat\knowledge_graph.py
def checkDatatypeProblem(self):
    """
    Count the number of literal that do not match the data type indicated.

    Returns:
        int: A integer that is the number of literal with datatype problem.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            dataTypeProblem = 0
            triples = q.getAllTriplesSPO(url)
            if isinstance(triples,list):
                for triple in triples:
                    obj = triple.get('o')
                    value = obj.get('value')
                    if utils.checkURI(value) == False:
                        dataType = obj.get('datatype')
                        if isinstance(dataType,str):
                            regex = utils.getRegex(dataType)
                            if regex is not None:
                                result = utils.checkString(regex,value)
                                if result == False:
                                    dataTypeProblem = dataTypeProblem + 1
                return dataTypeProblem
            else:
                return "Can't recover triples from the endpoint"
        except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
            return 'SPARQL endpoint offline'
        except Exception as e:
            return e
    else:
        return 'SPARQL endpoint absent'

checkDeprecatedClassesProp()

Check if deprecated classes and properties are used in the KG.

Returns:

Name Type Description
list

A list that contains deprecated classes and properties used in the KG.

Source code in kgheartbeat\knowledge_graph.py
def checkDeprecatedClassesProp(self):
    """
    Check if deprecated classes and properties are used in the KG.

    Returns:
        list: A list that contains  deprecated classes and properties used in the KG.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            deprecated = q.getDeprecated(url)
        except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
            return 'SPARQL endpoint offline'
        except Exception as e:
            deprecated = e

        return deprecated
    else:
        return 'SPARQL endpoint absent'            

checkDownload()

Check if the link for download the KG as rdf dump is present and online.

Returns:

Name Type Description
bool

A boolean that represent the dump link availability (True = Online and False = Offline).

Source code in kgheartbeat\knowledge_graph.py
def checkDownload(self):
    """
    Check if the link for download the KG as rdf dump is present and online.

    Returns:
        bool: A boolean that represent the dump link availability (True = Online and False = Offline). 

    """
    resources = aggregator.getOtherResources(self.id)
    resources = utils.insertAvailability(resources)
    available = utils.checkAvailabilityForDownload(resources)

    return available

checkEmptyLabel()

Count the number of empty label (if any) in the dataset.

Returns:

Name Type Description
int

An integer that is the number of empty label is SPQRQL endpoint is online.

Source code in kgheartbeat\knowledge_graph.py
def checkEmptyLabel(self):
    """
    Count the number of empty label (if any) in the dataset.

    Returns:
        int: An integer that is the number of empty label is SPQRQL endpoint is online.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            labels = q.getLabel(url)
            emptyL = 0
            for label in labels:
                if utils.checkURI(label) == False:
                    if label == '':
                        emptyL = emptyL + 1
            return emptyL
        except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
            return 'SPARQL endpoint offline'
        except Exception as e:
            return e
    else:
        return 'SPARQL endpoint absent'

checkEndpointAv()

Check the SPARQL endpoint availability.

Returns:

Name Type Description
bool

A boolean that represent the SPARQL endpoint availability (True = Online and False = Offline).

Source code in kgheartbeat\knowledge_graph.py
def checkEndpointAv(self):
    """Check the SPARQL endpoint availability.

    Returns:
        bool: A boolean that represent the SPARQL endpoint availability (True = Online and False = Offline).
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    try:
        result = q.checkEndPoint(url)
        if isinstance(result,bytes):
            newUrl = utils.checkRedirect(url)
            result = q.checkEndPoint(newUrl)
            if isinstance(result,bytes):
                available = False
            else:
                available = True
        else:
            available = True
    except:
        available = False

    return available

checkExample()

Check if query examples are provided with the KG. This information is obtained by analyzing the KG metadata, in particular, the field other resources.

Returns:

Name Type Description
bool

A boolean that is True if there are any query examples , False otherwise.

Source code in kgheartbeat\knowledge_graph.py
def checkExample(self):
    """
    Check if query examples are provided with the KG. This information is obtained by analyzing the KG metadata, in particular, the field other resources.

    Returns:
        bool: A boolean that is True if there are any query examples , False otherwise.
    """
    resources = aggregator.getOtherResources(self.id)
    resources = utils.insertAvailability(resources)
    otResources = utils.toObjectResources(resources)
    example = False
    for j in range(len(otResources)):
        if isinstance(otResources[j].format,str):
            if 'example' in otResources[j].format:
                example = True
        if isinstance(otResources[j].title,str):
            if 'example' in otResources[j].title:
                example = True

    return example

checkFPViolations()

Check for functional properties with inconsistent value, analyzing all triples with predicate owl:FunctionalProperty and checking if there is any violations.

Returns:

Name Type Description
int

An integer that is the number of triples with functional property violations.

Source code in kgheartbeat\knowledge_graph.py
def checkFPViolations(self):
    """
    Check for functional properties with inconsistent value, analyzing all triples with predicate owl:FunctionalProperty and checking if there is any violations.

    Returns:
        int: An integer that is the number of triples with functional property violations.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            violationFP = []
            triplesFP = q.getFP(url)
            for triple in triplesFP:
                s = triple.get('s')
                subject1 = s.get('value')
                o = triple.get('o')
                obj1 = o.get('value')
                for triple2 in triplesFP:
                    s = triple2.get('s')
                    subject2 = s.get('value')
                    o = triple2.get('o')
                    obj2 = o.get('value')
                    if subject1 == subject2 and obj1 != obj2:
                        violationFP.append(triple)
            return len(violationFP)
        except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
            return 'SPARQL endpoint offline'
        except Exception as e:
            return e
    else:
        return 'SPARQL endpoint absent'

checkHTTPS()

Check if data exchange on the SPARQL endpoint takes place on HTTPS protocol.

Returns:

Name Type Description
bool

A boolean that is True if HTTPS is used, Flase otherwise.

Source code in kgheartbeat\knowledge_graph.py
def checkHTTPS(self):
    """
    Check if data exchange on the SPARQL endpoint takes place on HTTPS protocol.

    Returns:
        bool: A boolean that is True if HTTPS is used, Flase otherwise.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            isSecure = utils.checkhttps(url)
            if isSecure == True or isinstance(isSecure,list): #IF QUERY ON THE SPARQL ENDPOINT RETURN A RESULT IT IS A LIST, SO URL WITH HTTPS WORKS 
                return True
            else:
                return False
        except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
            return 'SPARQL endpoint offline'
        except:
            return False
    else:
        return 'SPARQL endpoint absent'

checkIFPViolations()

Check for invalid usage of inverse-functional properties, analyzing all triples with predicate owl:InverseFunctionalProperty and checking if there is any violations.

Returns:

Name Type Description
int

An integer that is the number of triples with inverse-functional properties violations.

Source code in kgheartbeat\knowledge_graph.py
def checkIFPViolations(self):
    """
    Check for invalid usage of inverse-functional properties, analyzing all triples with predicate owl:InverseFunctionalProperty and checking if there is any violations. 

    Returns:
        int: An integer that is the number of triples with inverse-functional properties violations.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            violationIFP = []
            triplesIFP = q.getIFP(url)
            for triple in triplesIFP:
                s = triple.get('s')
                subject1 = s.get('value')
                o = triple.get('o')
                obj1 = o.get('value')
                for triple2 in triplesIFP:
                    s = triple2.get('s')
                    subject2 = s.get('value')
                    o = triple2.get('o')
                    obj2 = o.get('value')
                    if obj1 == obj2 and subject1 != subject2:
                        violationIFP.append(triple)
            return len(violationIFP)
        except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
            return 'SPARQL endpoint offline'
        except Exception as e:
            return e
    else:
        return 'SPARQL endpoint absent'

Check if there are inactive link associated with the KG.

Returns:

Name Type Description
bool

A boolean that represent if there are any inactive links associeted with the KG.

Source code in kgheartbeat\knowledge_graph.py
def checkInactiveLinks(self):
    """
    Check if there are inactive link associated with the KG.

    Returns:
        bool: A boolean that represent if there are any inactive links associeted with the KG.
    """
    resources = aggregator.getOtherResources(self.id)
    resources = utils.insertAvailability(resources)
    resourcesObj = utils.toObjectResources(resources)
    inactiveLink = False
    for link in resourcesObj:
        if link.status == 'offline':
            inactiveLink = True

    return inactiveLink

checkMisplacedClasses()

Check if the classes are used incorrectly, classes are used in the position of the predicate.

Returns:

Name Type Description
list

A list of misplaced classes.

Source code in kgheartbeat\knowledge_graph.py
def checkMisplacedClasses(self):
    """
    Check if the classes are used incorrectly, classes are used in the position of the predicate.

    Returns:
        list: A list of misplaced classes.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            misplacedClass = []
            properties = q.getAllProperty(url)
            allTriples = q.getAllTriplesSPO(url)
            found = False
            if isinstance(allTriples,list) and isinstance(properties,list):
                properties.sort()
                for i in range(len(allTriples)):
                    o = allTriples[i].get('o')
                    valueO = o.get('value')
                    s = allTriples[i].get('s')
                    valueS = s.get('value')
                    result = utils.checkURI(valueS)
                    if result == True:
                        r = utils.binarySearch(properties,0,len(properties)-1,valueS)
                        if r != -1:
                            found = True
                    resultO = utils.checkURI(valueO)
                    if found == False and resultO == True:
                        r2 = utils.binarySearch(properties,0,len(properties)-1,valueO)
                        if r2 != -1:
                            found = True
                    if found == True:
                        misplacedClass.append(valueS)
                        found = False
            else:
                misplacedClass = 'insufficient data'
        except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
            misplacedClass = 'SPARQL endpoint offline'
        except TimeoutError:
            misplacedClass = 'Timeout'
        except:
            misplacedClass = 'Could not process formulated query on indicated endpoint'

        return misplacedClass
    else:
        return 'SPARQL endpoint absent'

checkMisplacedProperty()

Check if the properties are used incorrectly, properties are used in the position of the subject.

Returns:

Name Type Description
list

A list of properties with misplaced propery problem.

Source code in kgheartbeat\knowledge_graph.py
def checkMisplacedProperty(self):
    """
    Check if the properties are used incorrectly, properties are used in the position of the subject.

    Returns:
        list: A list of properties with misplaced propery problem.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            misplacedProperty = []
            classes = q.getAllClasses(url)
            uriListP = q.getAllPredicate(url)
            if isinstance(uriListP,list) and isinstance(classes,list):
                for i in range(len(uriListP)):
                    p = uriListP[i]
                    result = utils.checkURI(p)
                    if result == True:
                        classes.sort()
                        r = utils.binarySearch(classes,0,len(classes)-1,p)
                        if r != -1:
                            misplacedProperty.append(p)
            else:
                misplacedProperty = 'insufficient data'
        except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
            misplacedProperty =  'SPARQL endpoint offline'
        except Exception as e:
            misplacedProperty = e

        return misplacedProperty
    else:
        return 'SPARQL endpoint absent'

checkOntologyHijacking()

Check for the ontology hijacking problem, if the SPARQL endpoint is online. This problem is present if there are a re-definition of classes or properties considered standard for LOD.

Returns:

Name Type Description
bool

A boolean that is True if there is a Ontology Hijacking problem, False otherwise.

Source code in kgheartbeat\knowledge_graph.py
def checkOntologyHijacking(self):
    """
    Check for the ontology hijacking problem, if the SPARQL endpoint is online.
    This problem is present if there are a re-definition of classes or properties considered standard for LOD.

    Returns:
        bool: A boolean that is True if there is a Ontology Hijacking problem, False otherwise.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            allType = q.getAllType(url)
            triplesOH = False
            if isinstance(allType,list):
                triplesOH = LOVAPI.searchTermsList(allType)
                if len(triplesOH) > 0:
                    hijacking = True
                else:
                    hijacking = False
            else:
                hijacking = 'Impossible to retrieve the terms defined in the dataset'
        except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
            hijacking = 'SPARQL endpoint offline'
        except:
            hijacking = 'Could not process formulated query on indicated endpoint'

        return hijacking
    else:
        return 'SPARQL endpoint absent'

checkRDFStr()

Check if RDF data structures is used in the KG.

Returns:

Name Type Description
bool

A boolean that is True if are used, False otherwise.

Source code in kgheartbeat\knowledge_graph.py
def checkRDFStr(self):
    """
    Check if RDF data structures is used in the KG. 

    Returns:
        bool: A boolean that is True if are used, False otherwise.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            rdf = q.checkRDFDataStructures(url)
        except:
            rdf = 'SPARQL endpoint offline'
    else:
        rdf = 'SPARQL endpoint absent'

    return rdf

checkReuseTerms()

Check usage of existing terms. This check is done using the Linked Open Vocabulary, a KG that contains vocabulary and terms standard for Linked Open Data.

Returns:

Name Type Description
bool

A boolean that is True if no new terms are defined, False otherwise.

Source code in kgheartbeat\knowledge_graph.py
def checkReuseTerms(self):
    """
    Check usage of existing terms. This check is done using the Linked Open Vocabulary, a KG that contains vocabulary and terms standard for Linked Open Data.

    Returns:
        bool: A boolean that is True if no new terms are defined, False otherwise.

    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            objList = []
            triplesO = q.getAllTypeO(url)
            for term in triplesO:
                objList.append(term)
            newTermsD = LOVAPI.searchTermsList(objList)
            if len(newTermsD) > 0:
                return False
            else:
                return True
        except:
            return 'SPARQL endpoint offline'
    else:
        return 'SPARQL endpoint absent'

checkReuseVocabs()

Check usage of existing vocabularies. This check is done using the Linked Open Vocabulary, a KG that contains vocabularies and terms standard for Linked Open Data.

Returns:

Name Type Description
bool

A boolean that is True if no new vocabularies are defined, False otherwise.

Source code in kgheartbeat\knowledge_graph.py
def checkReuseVocabs(self):
    """
    Check usage of existing vocabularies. This check is done using the Linked Open Vocabulary, a KG that contains vocabularies and terms standard for Linked Open Data.

    Returns:
        bool: A boolean that is True if no new vocabularies are defined, False otherwise.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            newVocab = []
            vocabs = q.getVocabularies(url)
            if isinstance(vocabs,list):
                for vocab in vocabs:
                    result = LOVAPI.findVocabulary(vocab)
                    if result == False:
                        newVocab.append(vocab)
                if len(newVocab) > 0:
                    return False
                else:
                    return True
            else:
                return 'Impossible to retrieve KG vocabularies'
        except:
            return 'SPARQL endpoint offline'
    else:
        return 'SPARQL endpoint absent'

checkSign()

Check if the KG is signed.

Returns:

Name Type Description
bool

A boolean that is True if is signed, False otherwise.l

Source code in kgheartbeat\knowledge_graph.py
def checkSign(self):
    """
    Check if the KG is signed.

    Returns:
        bool: A boolean that is True if is signed, False otherwise.l
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            sign = q.getSign(url)
            if isinstance(sign,int):
                if sign > 0:
                    signed = True
                else:
                    signed = False
            else:
                signed = False
        except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
            signed = 'SPARQL endpoint offline'
        except :
            signed = 'Could not process formulated query on indicated endpoint'
    else:
        signed = 'SPARQL endpoint absent'

    return signed

checkWhiteSpace()

Count the number of label that have a whitespace at the beginning or at the end.

Returns:

Name Type Description
int

An integer that is the number of label with whitespace problem if SPARQL endpoint is online.

Source code in kgheartbeat\knowledge_graph.py
def checkWhiteSpace(self):
    """
    Count the number of label that have a whitespace at the beginning or at the end.

    Returns:
        int: An integer that is the number of label with whitespace problem if SPARQL endpoint is online.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            wsCount = 0
            labels = q.getLabel(url)
            for label in labels:
                if utils.checkURI(label) == False:
                    if label != label.strip():
                        wsCount = wsCount + 1
            return wsCount
        except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
            return 'SPARQL endpoint offline'
        except Exception as e:
            return e
    else:
        return 'SPARQL endpoint offline' 

getAccessAtKG()

Get the ways in which you can access the KG. This information is retrived by analyzing the metadata and/or querying the SPARQL endpoint.

Returns:

Name Type Description
list

A list with all the links to access to the KG.

Source code in kgheartbeat\knowledge_graph.py
def getAccessAtKG(self):
    """
    Get the ways in which you can access the KG. This information is retrived by analyzing the metadata and/or querying the SPARQL endpoint.

    Returns:
        list: A list with all the links to access to the KG.
    """
    links = []
    url = aggregator.getSPARQLEndpoint(self.id)
    voidFile = utils.checkVoidFile(self.id)
    resources = aggregator.getOtherResources(self.id)
    resources = utils.insertAvailability(resources)
    links = links + utils.getLinkDownload(resources)
    if isinstance(url,str):
        links.append(url)
        try:
            urlList = q.checkDataDump(url)
            if isinstance(urlList,list):
                activeUrl = utils.getActiveDumps(urlList)
                links = links + activeUrl
        except:
            pass
    elif not isinstance(voidFile,bool):
        links = links + VoIDAnalyses.getDataDump(voidFile)

    links = list(dict.fromkeys(links)) #REMOVE DUPLICATES IN THE LIST

    return links

getAuthors()

Get all KG authors. This information is retrived from the SPARQL endpoint or VOID file.

Returns:

Name Type Description
list

A list that contains all the authors of the KG.

Source code in kgheartbeat\knowledge_graph.py
def getAuthors(self):
    """
    Get all KG authors. This information is retrived from the SPARQL endpoint or VOID file.

    Returns:
        list: A list that contains all the authors of the KG.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    voidFile = utils.checkVoidFile(self.id)
    if isinstance(url,str):
        try:
            authors = q.getCreator(url)
        except:
            authors = 'SPARQL endpoint offline'
            if not isinstance(voidFile,bool):
                authors = VoIDAnalyses.getCreators(voidFile)
    elif not isinstance(voidFile,bool):
        authors = VoIDAnalyses.getCreators(voidFile)
    else:
        authors = 'Impossible to retrieve vocabularies from SPARQL endopoint or VOID file'

    return authors

getCentrality()

Get the centrality of kg in the graph constructed with all the kg discoverable. At the first call of a function of the interlinking metric a file is created in the directory which contains the graph with all kg discoverable, this is to avoid the construction of the graph every time from scratch.

Returns:

Name Type Description
float

A float that is the centrality of the KG.

Source code in kgheartbeat\knowledge_graph.py
def getCentrality(self):
    """
    Get the centrality of kg in the graph constructed with all the kg discoverable.
    At the first call of a function of the interlinking metric a file is created in the directory which contains the graph with all kg discoverable, this is to avoid the construction of the graph every time from scratch.

    Returns:
        float: A float that is the centrality of the KG.
    """
    graph = utils.checkGraphFile()
    centrality = Graph.getCentrality(graph,self.id)
    centratility = "%.3f"%centrality

    return float(centrality)

getClusteringCoefficient()

Get the clustering coefficient of kg in the graph constructed with all the kg discoverable. At the first call of a function of the interlinking metric a file is created in the directory which contains the graph with all kg discoverable, this is to avoid the construction of the graph every time from scratch.

Returns:

Name Type Description
float

A float that represent a local clustering coefficient.

Source code in kgheartbeat\knowledge_graph.py
def getClusteringCoefficient(self):
    """
    Get the clustering coefficient of kg in the graph constructed with all the kg discoverable.
    At the first call of a function of the interlinking metric a file is created in the directory which contains the graph with all kg discoverable, this is to avoid the construction of the graph every time from scratch.

    Returns:
        float: A float that represent a local clustering coefficient.
    """
    graph = utils.checkGraphFile()
    lcc = Graph.getClusteringCoefficient(graph,self.id)
    lcc = "%.3f"%lcc

    return float(lcc)

getContributors()

Get all the KG contributors. This information is retrived from the SPARQL endpoint or VOID file.

Returns:

Name Type Description
list

A list that contains all the contributors to the KG.

Source code in kgheartbeat\knowledge_graph.py
def getContributors(self):
    """
    Get all the KG contributors. This information is retrived from the SPARQL endpoint or VOID file.

    Returns:
        list: A list that contains all the contributors to the KG.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    voidFile = utils.checkVoidFile(self.id)
    if isinstance(url,str):
        try:
            contributors = q.getContributors(url)
        except:
            contributors = 'SPARQL endpoint offline'
            if not isinstance(voidFile,bool):
                contributors = VoIDAnalyses.getContributors(voidFile)
    elif not isinstance(voidFile,bool):
        contributors = VoIDAnalyses.getContributors(voidFile)
    else:
        contributors = 'Impossible to retrieve vocabularies from SPARQL endopoint or VOID file'

    return contributors

getCreationDate()

Get the KG creation date. This information is retrived from the SPARQL endpoint or VOID file. False is returned if SPARQL endpoint is offline

Returns:

Name Type Description
string

A string that is the KG creation date

Source code in kgheartbeat\knowledge_graph.py
def getCreationDate(self):
    """
    Get the KG creation date. This information is retrived from the SPARQL endpoint or VOID file. False is returned if SPARQL endpoint is offline

    Returns:
        string: A string that is the KG creation date  
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    voidFile = utils.checkVoidFile(self.id)
    if isinstance(url,str):
        try:
            creationD = q.getCreationDateMin(url)
        except:
            creationD = False
            try:
                creationD = q.getCreationDate(url)
            except:
                creationD = False
            if not isinstance(voidFile,bool) and not isinstance(creationD,str):
                creationD = VoIDAnalyses.getCreationDate(voidFile)
    elif not isinstance(voidFile,bool):
        creationD = VoIDAnalyses.getCreationDate(voidFile)
    else:
        creationD = 'SPARQL endpoint and VoID absent'

    return creationD

getDegreeOfConnection()

Get the degree of connection of kg in the graph constructed with all the kg discoverable. At the first call of a function of the interlinking metric a file is created in the directory which contains the graph with all kg discoverable, this is to avoid the construction of the graph every time from scratch.

Returns:

Name Type Description
int

An integer that represent the degree of connection.

Source code in kgheartbeat\knowledge_graph.py
def getDegreeOfConnection(self):
    """
    Get the degree of connection of kg in the graph constructed with all the kg discoverable.
    At the first call of a function of the interlinking metric a file is created in the directory which contains the graph with all kg discoverable, this is to avoid the construction of the graph every time from scratch.

    Returns: 
        int: An integer that represent the degree of connection.
    """
    graph = utils.checkGraphFile()
    degree = Graph.getDegreeOfConnection(graph,self.id)
    return degree

getDescription()

Get the description of the KG by analyzing the metadata.

Returns:

Name Type Description
string

A string that contains a description of the KG.

Source code in kgheartbeat\knowledge_graph.py
def getDescription(self):
    """
    Get the description of the KG by analyzing the metadata.

    Returns:
        string: A string that contains a description of the KG.  
    """
    metadata = aggregator.getDataPackage(self.id)
    description = aggregator.getDescription(metadata)

    return description

getDisjointValue()

Get the disjoint value. It is calculated by counting the number of triples with predicate owl:disjointWith and then making the ratio between number of triples with that predicate and number of entities.

Returns:

Name Type Description
float

A float that represent the disjoint value if triples and entity is recovered correctly form SPARQL endpoint.

Source code in kgheartbeat\knowledge_graph.py
def getDisjointValue(self):
    """
    Get the disjoint value. It is calculated by counting the number of triples with predicate owl:disjointWith and then making the ratio between number of triples with that predicate and number of entities.

    Returns:
        float: A float that represent the disjoint value if triples and entity is recovered correctly form SPARQL endpoint.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            numDisjoint = q.getDisjoint(url)
            numEntities = q.getNumEntities(url)
            if not isinstance(numEntities,int):
                regex = []
                regex = q.checkUriRegex(url)
                pattern = q.checkUriPattern(url)
                for p in pattern:
                    newRegex = utils.trasforrmToRegex(p)
                    regex.append(newRegex)
                if len(regex) > 0:
                    numEntities = 0
                    for r  in regex:
                        numEntities = numEntities + q.getNumEntitiesRegex(url,r)
            if isinstance(numDisjoint,int):
                try:
                    numEntities = int(numEntities)
                    if numEntities > 0:
                        disjointValue = numDisjoint/numEntities
                        disjointValue = "%.3f"%disjointValue
                        disjointValue = float(disjointValue)
                    else:
                        disjointValue = 'insufficient data'
                except:
                    disjointValue = 'insufficient data'   

                return disjointValue     
        except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
            return 'SPARQL endpoint offline'   
        except Exception as e:
            return e
    else:
        return 'SPARQL endpoint absent'

getExtensionaConc()

Get the extensional conciseness value, it is calculated by the following formula: 1.0 - #duplicated triples (calculated with Bloom filter algorithm) / #triples in the dataset.

Returns:

Name Type Description
float

A float that is the extensional conciseness value.

Source code in kgheartbeat\knowledge_graph.py
def getExtensionaConc(self):
    """
    Get the extensional conciseness value, it is calculated by the following formula: 1.0 - #duplicated triples (calculated with Bloom filter algorithm) / #triples in the dataset.

    Returns:
        float: A float that is the extensional conciseness value.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            allTriples = q.getAllTriplesSPO(url)
            tripleList = []
            duplicate = []
            if isinstance(allTriples,list):
                if len(allTriples)> 0:    
                    for i in range(len(allTriples)):
                        s = allTriples[i].get('s')
                        p = allTriples[i].get('p')
                        o = allTriples[i].get('o')
                        subject = s.get('value')
                        predicate = p.get('value')
                        object = o.get('value')
                        triple = subject + predicate + object
                        tripleList.append(triple)
                    bloomF = BloomFilter(len(tripleList),0.05)
                    print("Size of bit array:{}".format(bloomF.size))
                    print("False positive Probability:{}".format(bloomF.fp_prob))
                    print("Number of hash functions:{}".format(bloomF.hash_count))
                    for i in range(len(tripleList)):
                        found = bloomF.check(tripleList[i])
                        if found == False:
                            bloomF.add(tripleList[i])
                        elif found == True:
                            duplicate.append(tripleList[i])

                    if len(allTriples) > 0:
                        exC = 1.0 - (len(duplicate)/len(allTriples)) # From: Evaluating the Quality of the LOD Cloud: An Empirical Investigation (Ruben Verborgh)
                        exC = "%.3f"%exC
                        exC = float(exC)
                    else:
                        exC = 'insufficient data'
                else:
                    exC = '0 triples retrieved from the endpoint'
            else:
                exC = 'insufficient data'
        except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
            exC = 'SPARQL endpoint offline'
        except:
            exC = 'Could not process formulated query on indicated endpoint'

        return exC
    else:
        return 'SPARQL endpoint absent'

getExternalProvider()

Return a dict with all external provider the key is the id of the KG it is connected to and the value is the number of triples connected, this information is obtained by analyzing the metadata.

Returns:

Name Type Description
dict

A dict with all external provider.

Source code in kgheartbeat\knowledge_graph.py
def getExternalProvider(self):
    """
    Return a dict with all external provider the key is the id of the KG it is connected to and the value is the number of triples connected, this information is obtained by analyzing the metadata.

    Returns:
        dict: A dict with all external provider.
    """

    extLinks = aggregator.getExternalLinks(self.id)

    return extLinks

getFrequencyUp()

Get the KG update frequency. This information is retrived from SPARQL endpoint or VOID file.

Returns:

Name Type Description
string

A string that contains the KG update frequency.

Source code in kgheartbeat\knowledge_graph.py
def getFrequencyUp(self):
    """
    Get the KG update frequency. This information is retrived from SPARQL endpoint or VOID file.

    Returns:
        string: A string that contains the KG update frequency.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    voidFile = utils.checkVoidFile(self.id)
    if isinstance(url,str):
        try:
            frequency = q.getFrequency(url)
        except:
            frequency = 'SPARQL endpoint offline'
            if not isinstance(voidFile,bool):
                frequency = VoIDAnalyses.getFrequency(voidFile)
    elif not isinstance(voidFile,bool):
        frequency = VoIDAnalyses.getFrequency(voidFile)
    else:
        frequency = 'SPARQL endpoint and VoID file absent'

    return frequency

getIntensionalConc()

Get the intensional conciseness value, it is calculated by the following formula: 1.0 - #duplicated properties (calculated with Bloom filter algorithm)/#triples in the dataset.

Returns:

Name Type Description
float

A float that is the intensional conciseness value.

Source code in kgheartbeat\knowledge_graph.py
def getIntensionalConc(self):
    """
    Get the intensional conciseness value, it is calculated by the following formula: 1.0 - #duplicated properties (calculated with Bloom filter algorithm)/#triples in the dataset.

    Returns:
        float: A float that is the intensional conciseness value.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            allProperty = q.getAllPropertySP(url)
            triplePropList = []
            duplicateP = []
            if isinstance(allProperty,list):
                if len(allProperty) > 0:
                    for i in range(len(allProperty)):
                        s = allProperty[i].get('s')
                        p = allProperty[i].get('p')
                        subP = s.get('value')
                        predP = p.get('value')
                        tripleProp = subP + predP
                        triplePropList.append(tripleProp)
                    bloomF2 = BloomFilter(len(triplePropList),0.05)
                    for j in range(len(triplePropList)):
                        found = bloomF2.check(triplePropList[j])
                        if found == False:
                            bloomF2.add(triplePropList[j])
                        elif found == True:
                            duplicateP.append(triplePropList[j])
                    if len(allProperty) > 0:
                        intC = 1.0 - (len(duplicateP)/len(allProperty))
                        intC = "%.3f"%intC
                        intC = float(intC)
                    else:
                        intC = 'insufficient data'
                else:
                    intC = '0 properties retrieved from the endpoint'
            else:
                intC = 'insufficient data'
        except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
            intC = 'SPARQL endpoint offline'
        except:
            intC = 'Could not process formulated query on indicated endpoint'

        return intC
    else:
        return 'SPARQL endpoint absent'

getInterlinkingComp()

Calcuate the interlinking completeness. It is calculated by the ratio between the number of linked triples and number of all triples in the dataset.

Returns:

Name Type Description
int

An integer that is the interlinking completeness of the KG.

Source code in kgheartbeat\knowledge_graph.py
def getInterlinkingComp(self):
    """
    Calcuate the interlinking completeness. It is calculated by the ratio between the number of linked triples and number of all triples in the dataset.

    Returns:
        int: An integer that is the interlinking completeness of the KG.
    """
    externalLinks = aggregator.getExternalLinks(self.id)
    exLinksObj = utils.toObjectExternalLinks(externalLinks)
    triplesL = 0
    for i in range(len(exLinksObj)): #COUNTING THE NUMBER OF TRIPLES CROSS EXTERNAL LINK LIST IN THE METADATA
        link = exLinksObj[i]
        value = link.value
        value = str(link.value)
        value = re.sub("[^\d\.]", "",value) #CHECK IF THE VALUE IS A NUMBER
        value = int(value)
        triplesL = triplesL + value
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            triples = q.getNumTripleQuery(url) #COUNT THE NUMBER OF TRIPLES WITH A SPARQL QUERY
        except:   #IF SPARQL ENDPOINT IS OFFLINE, COUNT THE TRIPLES BY ANALYZING THE METADATA
            triples = 'SPARQL endpoint offline'
            metadata = aggregator.getDataPackage(self.id)
            triples = aggregator.getTriples(metadata)
    else:
        triples = 'SPARQL endpoint and VoID file absent'

    try:
        triplesL = int(triplesL)
        triples = int(triples)
        if triples > 0:
            iCompl = (triplesL/triples)
            iCompl = "%.2f"%iCompl
            iCompl = float(iCompl)
        else:
            iCompl = 'Insufficient data'
    except:
        iCompl = 'Insufficient data'

    return iCompl

getLanguages()

Get the languages supported by the KG. This information is retrieved by querying the SPARQL endpoint.

Returns:

Name Type Description
list

A list with all the languages supprted by the KG.

Source code in kgheartbeat\knowledge_graph.py
def getLanguages(self):
    """
    Get the languages supported by the KG. This information is retrieved by querying the SPARQL endpoint.

    Returns:
        list: A list with all the languages supprted by the KG.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            languages = q.getLangugeSupported(url)
        except:
            languages = 'SPARQL endpoint offline'
    else:
        languages = 'SPARQL endpoint absent'

    return languages

getLastUp()

Get the elapsed time since the last modification (in days).

Returns:

Name Type Description
string

A string that represent the days that have passed since the last modification.

Source code in kgheartbeat\knowledge_graph.py
def getLastUp(self):
    """
    Get the elapsed time since the last modification (in days).

    Returns:
        string: A string that represent the days that have passed since the last modification.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    voidFile = utils.checkVoidFile(self.id)
    if isinstance(url,str):
        try:
            modificationD = q.getModificationDateMax(url)
        except:
            modificationD = False
            try:
                modificationD = q.getModificationDate(url)
            except:
                modificationD = False
            if not isinstance(voidFile,bool) and not isinstance(modificationD,str):
                modificationD = VoIDAnalyses.getCreationDate(voidFile)
    elif not isinstance(voidFile,bool):
        modificationD = VoIDAnalyses.getCreationDate(voidFile)
    else:
        modificationD = 'SPARQL endpoint and VoID absent'
    try:
        today = datetime.date.today()
        todayFormatted = today.strftime("%Y-%m-%d")
        todayDate =  datetime.datetime.strptime(todayFormatted, "%Y-%m-%d").date()
        modificationD = datetime.datetime.strptime(modificationD, "%Y-%m-%d").date()
        delta = (todayDate - modificationD).days
    except:
        delta = 'Insufficient data'


    return delta

getLatency()

Get the latency of the sparql endpoint, is the time passed between the request for a triple and when is returned. The value returned is the average latency of the 5 attempts performed.

Returns:

Name Type Description
float

A float that is the average latency if SPARQL endpoint is online.

Source code in kgheartbeat\knowledge_graph.py
def getLatency(self):
    """
    Get the latency of the sparql endpoint, is the time passed between the request for a triple and when is returned.
    The value returned is the average latency  of the 5 attempts performed.

    Returns:
        float: A float that is the average latency if SPARQL endpoint is online.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            latency = q.testLatency(url)
            sumL = sum(latency)
            average = sumL/len(latency)
            return average
        except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
            return 'SPARQL endpoint offline'
        except Exception as e:
            return e
    else:
        return 'SPARQL endpoint absent'

getLicenseHR()

Get the human-redeable license, search for a label on the triples in the KG.

Returns:

Name Type Description
list

A list which contain all the human-redeable license founded in the KG.

Source code in kgheartbeat\knowledge_graph.py
def getLicenseHR(self):
    """
    Get the human-redeable license, search for a label on the triples in the KG.

    Returns:
        list: A list which contain all the human-redeable license founded in the KG.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    try:
        license = q.checkLicenseHR(url)
    except Exception as e:
        license = e

    return license

getLicenseMR()

Return the machine-redeable license of the kg, checking on the SPARQL endpopint, in the metadata and in the void file .

Returns:

Name Type Description
string

A string that represent the machine-redeable license of the KG.

Source code in kgheartbeat\knowledge_graph.py
def getLicenseMR(self):
    """
    Return the machine-redeable license of the kg, checking on the SPARQL endpopint, in the metadata and in the void file .

    Returns:
        string: A string that represent the machine-redeable license of the KG.
    """
    metadata = aggregator.getDataPackage(self.id)

    licenseM = aggregator.getLicense(metadata) #CHECKING IN THE METADATA
    if isinstance(licenseM,str): 
        return licenseM   #IF LICENSE IS INDICATED IN THE METADATE, RETURN IT

    try:
        licenseQ = q.checkLicenseMR2(aggregator.getSPARQLEndpoint(self.id)) #CHECKING ON THE SPARQL ENDPOINT
        if isinstance(licenseQ,list):
            return licenseQ
    except Exception as e:
        return e

    resources = aggregator.getOtherResources(self.id)
    resources = utils.insertAvailability(resources)
    otResources = utils.toObjectResources(resources)
    urlV = utils.getUrlVoID(otResources)
    if isinstance(urlV,str):  # CHECKING IF VOID FILE IS AVAILABLE
        try:
            voidFile = VoIDAnalyses.parseVoID(urlV)
            void = True
        except:
            try:
                voidFile = VoIDAnalyses.parseVoIDTtl(urlV)
                void = True
            except:
                void = False 
    if void == True:
        licenseV = VoIDAnalyses.getLicense(voidFile)  #GETTING LICENSE FROM THE VOID FILE
        if isinstance(licenseV,str):
            return licenseV

getModificationDate()

Get the KG modification date. This information is retrived from SPARQL endpoint or VOID file. False is returned if SPARQL endpoint is offline.

Returns:

Name Type Description
string

A string that contains a KG modification date.

Source code in kgheartbeat\knowledge_graph.py
def getModificationDate(self):
    """
    Get the KG modification date. This information is retrived from SPARQL endpoint or VOID file. False is returned if SPARQL endpoint is offline.

    Returns:
        string: A string that contains a KG modification date.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    voidFile = utils.checkVoidFile(self.id)
    if isinstance(url,str):
        try:
            modificationD = q.getModificationDateMax(url)
        except:
            modificationD = False
            try:
                modificationD = q.getModificationDate(url)
            except:
                modificationD = False
            if not isinstance(voidFile,bool) and not isinstance(modificationD,str):
                modificationD = VoIDAnalyses.getCreationDate(voidFile)
    elif not isinstance(voidFile,bool):
        modificationD = VoIDAnalyses.getCreationDate(voidFile)
    else:
        modificationD = 'SPARQL endpoint and VoID absent'

    return modificationD

getName()

Get the title of the KG by analyzing the metadata.

Returns:

Name Type Description
string

A string that contains the title of the KG.

Source code in kgheartbeat\knowledge_graph.py
def getName(self):
    """
    Get the title of the KG by analyzing the metadata.

    Returns:
        string: A string that contains the title of the KG.
    """
    metadata = aggregator.getDataPackage(self.id)
    title = aggregator.getNameKG(metadata)

    return title

getNumEntities()

Count the number of entities in the dataset. This information can be obtained by a SPARQL endpoint or analyzing the VoID file.

Returns:

Name Type Description
int

An integer that is the number of entities in the KG.

Source code in kgheartbeat\knowledge_graph.py
def getNumEntities(self):
    """
    Count the number of entities in the dataset. This information can be obtained by a SPARQL endpoint or analyzing the VoID file.

    Returns:
        int: An integer that is the number of entities in the KG.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    voidFile = utils.checkVoidFile(self.id)
    if isinstance(url,str):
        try:
            entities = q.getNumEntities(url)
            try:
                entities = int(entities)
                return entities
            except:  #IF WITH THE FIRST QUERY WE DON'T GET THE RESULT, WE TRY TO COUNT THE NUMBER OF ENTITIES BY COUNTING THE NUMBER OF TRIPLES THAT MATH WITH THEKG URI REGEX
                #GET THE REGEX OF THE URLs USED
                regex = []
                try:
                    regex = q.checkUriRegex(url)
                except:
                    regex = 'Could not process formulated query on indicated enpdoint'

                #CHECK IF IS INDICATED A URI SPACE INSTEAD OF A REGEX AND WE TRAFORM IT TO REGEX
                try:    
                    pattern = q.checkUriPattern(url)  
                    if isinstance(pattern,list):
                        for i in range(len(pattern)): 
                            newRegex = utils.trasforrmToRegex(pattern[i])
                            regex.append(newRegex)
                except:
                    pattern = 'Could not process formulated query on indicated enpdoint'

                #NOW COUNT THE ENITITIES USING THE REGEX
                try:
                    if len(regex) > 0:
                        entities = 0
                        for i in range(len(regex)):
                            entities = entities + q.getNumEntitiesRegex(url,regex[i])
                    else:
                        entities = 'insufficient data'
                except Exception as e:
                    entities = e

                return entities
        except:
            if not isinstance(voidFile,bool):
                entities = VoIDAnalyses.getNumEntities(voidFile)
                return entities
    elif not isinstance(voidFile,bool):
        entities = VoIDAnalyses.getNumEntities(voidFile)
        return entities
    else:
        return 'SPARQL endpoint and VoID file absent'

getNumLabels()

Count the number of label on the triples in the KG. This count is done by using a query on the SPARQL endpoint.

Returns:

Name Type Description
int

An integer that is the number of label in the KG.

Source code in kgheartbeat\knowledge_graph.py
def getNumLabels(self):
    """
    Count the number of label on the triples in the KG. This count is done by using a query on the SPARQL endpoint.

    Returns:
        int: An integer that is the number of label in the KG.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            numLabel = q.getNumLabel(url)
        except:
            numLabel = 'SPARQL endpoint offline'
    else:
        numLabel = 'SPARQL endpoint absent'

    return numLabel

getNumProperty()

Get the number of property in the KG. This information is retrived by executing a query on the SPARQL endpoint.

Returns:

Name Type Description
int

An integer that is the number of properties in the KG.

Source code in kgheartbeat\knowledge_graph.py
def getNumProperty(self):
    """
    Get the number of property in the KG. This information is retrived by executing a query on the SPARQL endpoint.

    Returns:
        int: An integer that is the number of properties in the KG.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            numProperty = q.numberOfProperty(url)
        except:
            numProperty = 'SPARQL endpoint offline'
    else:
        numProperty = 'SPARQL endpoint absent'

    return numProperty

getNumTriples()

Get the number of triples in the KG. This information can be obtained by SPARQL endpoint or analyzing the metadata of the dataset.

Returns:

Name Type Description
int

An integer that is the number of triples.

Source code in kgheartbeat\knowledge_graph.py
def getNumTriples(self):
    """
    Get the number of triples in the KG. This information can be obtained by SPARQL endpoint or analyzing the metadata of the dataset.

    Returns:
        int: An integer that is the number of triples.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    metadata = aggregator.getDataPackage(self.id)
    if isinstance(url,str):
        try:
            triples = q.getNumTripleQuery(url)
        except:
            triples = 'SPARQL endpoint offline'
            triples = aggregator.getTriples(metadata)
    else:
        triples = aggregator.getTriples(metadata)

    return triples

getNumbBN()

Get the blank node number. This is obtained by querying the SPARQL endpoint.

Returns:

Name Type Description
int

An integer that represent the number of blank node in the KG.

Source code in kgheartbeat\knowledge_graph.py
def getNumbBN(self):
    """
    Get the blank node number. This is obtained by querying the SPARQL endpoint.

    Returns:    
        int: An integer that represent the number of blank node in the KG.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            numBlankN = q.numBlankNode(url)
        except:
            numBlankN = 'SPARQL endpoint offline'
    else:
        numBlankN = 'SPARQL endpoint absent'

    return numBlankN

getPageRank()

Get the pagerank of KG based on the graph constructed with all the kg discoverable.

Returns:

Name Type Description
float

A float that represent the pagerank value.

Source code in kgheartbeat\knowledge_graph.py
def getPageRank(self):
    """
    Get the pagerank of KG based on the graph constructed with all the kg discoverable.

    Returns:
        float: A float that represent the pagerank value.
    """
    graph = utils.checkGraphFile()
    pageRank = Graph.getPageRank(graph,self.id)
    pageRank = "%.4f"%pageRank

    return float(pageRank)

getPercentageUpData(modificationDate)

Get the percentage of updated data. The percentage is calcualted based on the modificationDate given as a parameter.

Returns:

Name Type Description
string

A percentage of updated data.

Source code in kgheartbeat\knowledge_graph.py
def getPercentageUpData(self,modificationDate):
    """
    Get the percentage of updated data. The percentage is calcualted based on the modificationDate given as a parameter.

    Returns:
        string: A percentage of updated data.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            numTriplesUp = q.getNumUpdatedData(url,modificationDate)
        except:
            numTriplesUp = 'SPARQL endpoint offline'
    else:
        numTriplesUp = 'SPARQL endpoint absent'

    return numTriplesUp

getPublishers()

Get all the KG pubilshers. This information is retrived from the SPARQL endpoint or VOID file.

Returns:

Name Type Description
list

A list that contains the publishers of the KG.

Source code in kgheartbeat\knowledge_graph.py
def getPublishers(self):
    """
    Get all the KG pubilshers. This information is retrived from the SPARQL endpoint or VOID file.

    Returns:
        list: A list that contains the publishers of the KG.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    voidFile = utils.checkVoidFile(self.id)
    if isinstance(url,str):
        try:
            publishers = q.getPublisher(url)
        except:
            publishers = 'SPARQL endpoint offline'
            if not isinstance(voidFile,bool):
                publishers = VoIDAnalyses.getPublishers(voidFile)
    elif not isinstance(voidFile,bool):
        publishers = VoIDAnalyses.getPublishers(voidFile)
    else:
        publishers = 'Impossible to retrieve vocabularies from SPARQL endopoint or VOID file'

    return publishers

getRegex()

Return the uri regex of the KG. This check id done by using a query on the SPARQL endpoin or by analyzing the VoID file if available.

Returns:

Name Type Description
list

A list with the URI regex

Source code in kgheartbeat\knowledge_graph.py
def getRegex(self):
    """
    Return the uri regex of the KG. This check id done by using a query on the SPARQL endpoin or by analyzing the VoID file if available.

    Returns:
        list: A list with the URI regex
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    voidFile = utils.checkVoidFile(self.id)
    if isinstance(url,str):
        regex = []
        try:
            regex = q.checkUriRegex(url)
        except Exception as e:
            regex = 'SPARQL endpoint offline'
            if not isinstance(voidFile,bool):
                regex = VoIDAnalyses.getUriRegex(voidFile) 
        #CHECK IF IS INDICATED A URI SPACE INSTEAD OF A REGEX AND WE TRAFORM IT TO REGEX
        try:    
            pattern = q.checkUriPattern(url)  
            if isinstance(pattern,list):
                for i in range(len(pattern)): 
                    newRegex = utils.trasforrmToRegex(pattern[i])
                    regex.append(newRegex)
        except:
            pattern = 'SPARQL endpoint offline'
    elif not isinstance(voidFile,bool):
        regex = VoIDAnalyses.getUriRegex(voidFile)
    else:
        regex = 'SPARQL endpint absent'

    return regex

getSameAsChains()

Return the number of sameAs chains, counting the triples with the predicate equal to owl:sameAs.

Returns:

Name Type Description
int

A integer that is the number of sameAs chains.

Source code in kgheartbeat\knowledge_graph.py
def getSameAsChains(self):
    """
    Return the number of sameAs chains, counting the triples with the predicate equal to owl:sameAs.

    Returns:
        int: A integer that is the number of sameAs chains.
    """
    try:
        url = aggregator.getSPARQLEndpoint(self.id)
        if isinstance(url,str):
            numSameAs = q.getSameAsChains(url)
        else:
            numSameAs = 'SPARQL endpoint absent'
    except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
        numSameAs = 'SPARQL endpoint offline'
    except Exception as e:
        numSameAs = e

    return numSameAs

getSerializationFormat()

Get the KG serialization formats. This information is retrived by executing a query on the SPARQL endpoint or from VoID file if available.

Returns:

Name Type Description
list

A list that contains all the serialization formats supported by the KG.

Source code in kgheartbeat\knowledge_graph.py
def getSerializationFormat(self):
    """
    Get the KG serialization formats. This information is retrived by executing a query on the SPARQL endpoint or from VoID file if available.

    Returns:
        list: A list that contains all the serialization formats supported by the KG.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    voidFile = utils.checkVoidFile(self.id)
    if isinstance(url,str):
        try:
            formats = q.checkSerialisationFormat(url)
        except:
            formats = 'SPARQL endpoint offline'
            if not isinstance(voidFile,bool):
                formats = VoIDAnalyses.getSerializationFormats(voidFile)
    elif not isinstance(voidFile,bool):
        formats = VoIDAnalyses.getSerializationFormats(voidFile)
    else:
        formats = 'SPARQL endpoint and VoID file absent'

    return formats

getSources()

Get the KG sources. This return a Sources object that contains three field: web, email, name.

Returns:

Type Description

Sources object: A Sources object that contain information about web address, email, name authors or maintainer.

Source code in kgheartbeat\knowledge_graph.py
def getSources(self):
    """
    Get the KG sources. This return a Sources object that contains three field: web, email, name.

    Returns:
        Sources object: A Sources object that contain information about web address, email, name authors or maintainer.
    """
    metadata = aggregator.getDataPackage(self.id)
    sources = aggregator.getSource(metadata)
    if sources == False:
        sourcesObj = Sources('Absent','Absent','Absent')
    else:
        sourcesObj = Sources(sources.get('web','Absent'),sources.get('name','Absent'),sources.get('email','Absent'))

    return sourcesObj  #use sourcesKG() to print information about sources

getThroughput()

Get the throughput of the sparql endpoint, is the number of triples obtained by the endpoint in one second. The value returned is the average thrpughput of the 5 attempts performed.

Returns:

Name Type Description
float

A float that represent the throughput of the SPARQL endpoint.

Source code in kgheartbeat\knowledge_graph.py
def getThroughput(self):
    """
    Get the throughput of the sparql endpoint, is the number of triples obtained by the endpoint in one second.
    The value returned is the average thrpughput of the 5 attempts performed.

    Returns:
        float: A float that represent the throughput of the SPARQL endpoint.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            tp = utils.getThroughput(url)
            sumTP = sum(tp)
            average = sumTP/len(tp)
            return average
        except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
            return 'SPARQL endpoint offline'
        except Exception as e:
            return e
    else:
        return 'SPARQL endpoint absent'

getURIsDef()

Check the URIs deferenceability. This test is done based on 5000 triples retrieved randomly from the SPARQL endpoint, and for each triple a GET requests is performed.

Returns:

Name Type Description
float

A float that represent a value which is the ratio between: number of deferenceable URIs and number of total URIs considered.

Source code in kgheartbeat\knowledge_graph.py
def getURIsDef(self):
    """
    Check the URIs deferenceability. This test is done based on 5000 triples retrieved randomly from the SPARQL endpoint, and for each triple a GET requests is performed.

    Returns:
        float: A float that represent a value which is the ratio between: number of deferenceable URIs and number of total URIs considered.

    """
    url = aggregator.getSPARQLEndpoint(self.id)
    try:
        defCount = 0
        uriCount = 0
        uris = q.getUris(url) #QUERY THAT GET 5000 RANDOM URI FROM THE ENDPOINT 
        for uri in uris:
            if utils.checkURI(uri) == True:
                uriCount = uriCount + 1
                try:
                    response = requests.get(uri,headers={"Accept":"application/rdf+xml"},stream=True)
                    if response.status_code == 200:
                        defCount = defCount +1
                except:
                    continue
        if uriCount > 0:        
            defValue = defCount / uriCount
        else:
            defValue = 'No uri retrieved from the endpoint'
    except: #IF QUERY FAILS (BECUASE SPARQL 1.1 IS NOT SUPPORTED) TRY TO CHECK THE DEFERETIABILITY BY FILTERING THE TRIPLES RECOVERED FOR OTHER CALCULATION (IF THEY ARE BEEN RECOVERED)
        try:
            uriCount = 0
            defCount = 0
            allTriples = q.getAllTriplesSPO(url)
            for i in range(5000):
                s = allTriples[i].get('s')
                value = s.get('value')
                if utils.checkURI(value):
                    uriCount = uriCount + 1
                    try:
                        response = requests.get(value,headers={"Accept":"application/rdf+xml"},stream=True)
                        if response.status_code == 200:
                            defCount = defCount +1
                    except:
                        continue
            if uriCount > 0:
                defValue = defCount / uriCount
            else:
                defValue = 'No uri found'
        except:
            defValue = 'Could not process formulated query on indicated endpoint'

    return defValue

getUndefinedClass()

Get the classes used without declaration.

Returns:

Name Type Description
list

A list that contains undefined classes

Source code in kgheartbeat\knowledge_graph.py
def getUndefinedClass(self):
    """
    Get the classes used without declaration.

    Returns:
        list: A list that contains undefined classes
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            allTriples = q.getAllTriplesSPO(url)
            allType = q.getAllType(url)
            toSearch = []
            found = False
            for i in range(len(allTriples)):
                s = allTriples[i].get('s')
                s = s.get('value')
                allType.sort()
                r = utils.binarySearch(allType,0,len(allType)-1,s)
                if r != -1:
                    found = True
                    break
                if found == False:
                    result = utils.checkURI(s)
                    if result == True:
                        toSearch.append(s)
                found = False
            undClasses = LOVAPI.searchTermsList(toSearch)
        except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
            return 'SPARQL endpoint offline'
        except Exception as e:
            return e

        return undClasses
    else:
        return 'SPARQL endpoint absent'

getUndefinedProp()

Get the properties used without declaration.

Returns:

Name Type Description
list

A list that contains a list of undefined properties.

Source code in kgheartbeat\knowledge_graph.py
def getUndefinedProp(self):
    """
    Get the properties used without declaration.

    Returns:
        list: A list that contains a list of undefined properties. 
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            uriListP = q.getAllPredicate(url)
            properties = q.getAllProperty(url)
            toSearch = []
            found = False
            for i in range(len(uriListP)):
                p = uriListP[i]
                properties.sort()
                r = utils.binarySearch(properties,0,len(properties)-1,p)
                if r != -1:
                    found = True
                    break
                if found == False:
                    result = utils.checkURI(p)
                    if result == True:
                        toSearch.append(p)
                found = False
            undProperties = LOVAPI.searchTermsList(toSearch)
        except (HTTPError,URLError,SPARQLExceptions.EndPointNotFound,socket.gaierror,SPARQLExceptions.EndPointInternalError,json.JSONDecodeError, SPARQLExceptions.QueryBadFormed,SPARQLExceptions.Unauthorized):
            undProperties = 'SPARQL endpoint offline'
        except :
            undProperties = 'Could not process formulated query on indicated endpoint'

        return undProperties

    else:
        return 'SPARQL endpoint absent'

getUri()

Get the URI of the KG by analyzing the metadata.

Returns:

Name Type Description
string

A tring that is the URI of the KG.

Source code in kgheartbeat\knowledge_graph.py
def getUri(self):
    """
    Get the URI of the KG by analyzing the metadata.

    Returns:
        string: A tring that is the URI of the KG.
    """
    metadata = aggregator.getDataPackage(self.id)
    sources = aggregator.getSource(metadata)
    url = sources.get('web','Absent')

    return url

getUriLenghtObj()

Get the uri's length in the object position. The returned value is a list in which the values are respectively min-max-average-standard deviation.

Returns:

Name Type Description
list

A list that contains all the URI in the object position

Source code in kgheartbeat\knowledge_graph.py
def getUriLenghtObj(self):
    """
    Get the uri's length in the object position. The returned value is a list in which the values are respectively min-max-average-standard deviation.

    Returns:
        list: A list that contains all the URI in the object position
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            uriListO = q.getAllObject(url)
            lengthtList = []
            for triple in uriListO:
                if utils.checkURI(triple) == True:
                    lengthtList.append(len(triple))
            sumLenghts = sum(lengthtList)
            avLenghts = sumLenghts/len(lengthtList) 
            avLenghts = str(avLenghts)
            avLenghts = avLenghts.replace('.',',')
            standardDeviationL = numpy.std(lengthtList)
            standardDeviationL = str(standardDeviationL)
            standardDeviationL = standardDeviationL.replace('.',',')
            minLenghtS = min(lengthtList)
            maxLenghtS = max(lengthtList)
            length = [minLenghtS,maxLenghtS,avLenghts,standardDeviationL]
        except:
            length = 'SPARQL endpoint offline'
    else:
        length = 'SPARQL endpoint absent'

    return length

getUriLenghtPr()

Get the uri's length in the predicate position. The returned value is a list in which the values are respectively min-max-average-standard deviation.

Returns:

Name Type Description
list

A list that contains URIs in the predicate position.

Source code in kgheartbeat\knowledge_graph.py
def getUriLenghtPr(self):
    """
    Get the uri's length in the predicate position. The returned value is a list in which the values are respectively min-max-average-standard deviation.

    Returns:
        list: A list that contains URIs in the predicate position.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            uriListP = q.getAllPredicate(url)
            lengthtList = []
            for triple in uriListP:
                if utils.checkURI(triple) == True:
                    lengthtList.append(len(triple))
            sumLenghts = sum(lengthtList)
            avLenghts = sumLenghts/len(lengthtList) 
            avLenghts = str(avLenghts)
            avLenghts = avLenghts.replace('.',',')
            standardDeviationL = numpy.std(lengthtList)
            standardDeviationL = str(standardDeviationL)
            standardDeviationL = standardDeviationL.replace('.',',')
            minLenghtS = min(lengthtList)
            maxLenghtS = max(lengthtList)
            length = [minLenghtS,maxLenghtS,avLenghts,standardDeviationL]
        except:
            length = 'SPARQL endpoint offline'
    else:
        length = 'SPARQL endpoint absent'

    return length

getUriLenghtSub()

Get the uri's length in the subject position. The returned value is a list in which the values are respectively min-max-average-standard deviation.

Returns:

Name Type Description
list

A list that contains all the URI in the KG.

Source code in kgheartbeat\knowledge_graph.py
def getUriLenghtSub(self):
    """
    Get the uri's length in the subject position. The returned value is a list in which the values are respectively min-max-average-standard deviation.

    Returns:
        list: A list that contains all the URI in the KG.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    if isinstance(url,str):
        try:
            lengthtList = []
            triples = q.getAllTriplesSPO(url)
            for triple in triples:
                s = triple.get('s')
                uri = s.get('value')
                if utils.checkURI(uri) == True:
                    lengthtList.append(len(uri))
            sumLenghts = sum(lengthtList)
            avLenghts = sumLenghts/len(lengthtList) 
            avLenghts = str(avLenghts)
            avLenghts = avLenghts.replace('.',',')
            standardDeviationL = numpy.std(lengthtList)
            standardDeviationL = str(standardDeviationL)
            standardDeviationL = standardDeviationL.replace('.',',')
            minLenghtS = min(lengthtList)
            maxLenghtS = max(lengthtList)
            length = [minLenghtS,maxLenghtS,avLenghts,standardDeviationL]
        except:
            length = 'SPARQL endpoint offline'
    else:
        length = 'SPARQL endpoint absent'

    return length

getVocabularies()

Get all the vocabularies used in the KG. This information is retrived from the SPARQL endpoint or VOID file.

Returns:

Name Type Description
list

A list that contains all the vocabularies used in the KG.

Source code in kgheartbeat\knowledge_graph.py
def getVocabularies(self):
    """
    Get all the vocabularies used in the KG. This information is retrived from the SPARQL endpoint or VOID file.

    Returns:
        list: A list that contains all the vocabularies used in the KG.
    """
    url = aggregator.getSPARQLEndpoint(self.id)
    voidFile = utils.checkVoidFile(self.id)
    if isinstance(url,str):
        try:
            vocabularies = q.getVocabularies(url)
        except:
            vocabularies = 'SPARQL endpoint offline'
            if not isinstance(voidFile,bool):  #IF SPARQL ENDPOINT IS OFFLINE TRY TO GET THE VOCABULARIES FROM VOID FILE
                vocabularies = VoIDAnalyses.getVocabularies(voidFile)
    elif not isinstance(voidFile,bool): #IF SPARQL ENDPOINT IS ABSENT TRY TO GET THE VOCABULARIES FROM VOID FILE
        vocabularies = VoIDAnalyses.getVocabularies(voidFile)
    else:
        vocabularies = 'Impossible to retrieve vocabularies from SPARQL endopoint or VOID file'

    return vocabularies