import { describe, expect, it } from "vitest" import LinkedDataLoader from "../../../src/Logic/Web/LinkedDataLoader" describe("LinkedDataLoader", () => { it("should compact a shop entry", async () => { const graph = { "@context": "http://schema.org", "@type": "LocalBusiness", "@id": "http://stores.delhaize.be/nl/ad-delhaize-munsterbilzen", "name": "AD Delhaize Munsterbilzen", "url": "http://stores.delhaize.be/nl/ad-delhaize-munsterbilzen", "logo": "https://stores.delhaize.be/build/images/web/shop/delhaize-be/favicon.ico", "image": "http://stores.delhaize.be/image/mobilosoft-testing?apiPath=rehab/delhaize-be/images/location/ad%20delhaize%20image%20ge%CC%81ne%CC%81rale%20%281%29%201652787176865&imageSize=h_500", "email": "", "telephone": "+3289413520", "address": { "@type": "PostalAddress", "streetAddress": "Waterstraat, 18", "addressLocality": "Bilzen", "postalCode": "3740", "addressCountry": "BE", }, "geo": { "@type": "GeoCoordinates", "latitude": 50.8906898, "longitude": 5.5260586, }, "openingHoursSpecification": [ { "@type": "OpeningHoursSpecification", "dayOfWeek": "Tuesday", "opens": "08:00", "closes": "18:30", }, { "@type": "OpeningHoursSpecification", "dayOfWeek": "Wednesday", "opens": "08:00", "closes": "18:30", }, { "@type": "OpeningHoursSpecification", "dayOfWeek": "Thursday", "opens": "08:00", "closes": "18:30", }, { "@type": "OpeningHoursSpecification", "dayOfWeek": "Friday", "opens": "08:00", "closes": "18:30", }, { "@type": "OpeningHoursSpecification", "dayOfWeek": "Saturday", "opens": "08:00", "closes": "18:30", }, { "@type": "OpeningHoursSpecification", "dayOfWeek": "Sunday", "opens": "08:00", "closes": "12:00", }, { "@type": "OpeningHoursSpecification", "dayOfWeek": "Monday", "opens": "12:00", "closes": "18:30", }, ], "@base": "https://stores.delhaize.be/nl/ad-delhaize-munsterbilzen", } const compacted = await LinkedDataLoader.compact(graph) expect(compacted.phone).equal("+32 89 41 35 20") }) it("should handle velopark data", async () => { const veloparkEntry = { "@context": { "xsd": "http://www.w3.org/2001/XMLSchema#", "schema": "http://schema.org/", "mv": "http://schema.mobivoc.org/", "dct": "http://purl.org/dc/terms#", "dbo": "http://dbpedia.org/ontology/", "gr": "http://purl.org/goodrelations/v1#", "vp": "https://data.velopark.be/openvelopark/vocabulary#", "vpt": "https://data.velopark.be/openvelopark/terms#", "PostalAddress": "schema:PostalAddress", "GeoCoordinates": "schema:GeoCoordinates", "GeoShape": "schema:GeoShape", "Map": "schema:Map", "ContactPoint": "schema:ContactPoint", "Language": "schema:Language", "OpeningHoursSpecification": "schema:OpeningHoursSpecification", "WebSite": "schema:WebSite", "PriceSpecification": "schema:PriceSpecification", "Photograph": "schema:Photograph", "Place": "schema:Place", "BicycleParkingStation": "mv:BicycleParkingStation", "Entrance": "mv:ParkingFacilityEntrance", "Exit": "mv:ParkingFacilityExit", "TimeSpecification": "mv:TimeSpecification", "Bicycle": "vp:Bicycle", "AllowedBicycle": "vp:AllowedBicycle", "BikeParkingFeature": "vp:BikeParkingFeature", "SecurityFeature": "vp:SecurityFeature", "PublicBicycleParking": "vpt:PublicBicycleParking", "ResidentBicycleParking": "vpt:ResidentBicycleParking", "BicycleLocker": "vpt:BicycleLocker", "RegularBicycle": "vpt:RegularBicycle", "ElectricBicycle": "vpt:ElectricBicycle", "CargoBicycle": "vpt:CargoBicycle", "TandemBicycle": "vpt:TandemBicycle", "CameraSurveillance": "vpt:CameraSurveillance", "PersonnelSupervision": "vpt:PersonnelSupervision", "ElectronicAccess": "vpt:ElectronicAccess", "BicyclePump": "vpt:BicyclePump", "MaintenanceService": "vpt:MaintenanceService", "ChargingPoint": "vpt:ChargingPoint", "LockerService": "vpt:LockerService", "ToiletService": "vpt:ToiletService", "BikeRentalService": "vpt:BikeRentalService", "BusinessEntity": "gr:BusinessEntity", "address": "schema:address", "geo": "schema:geo", "hasMap": "schema:hasMap", "url": "schema:url", "image": "schema:image", "contactPoint": "schema:contactPoint", "interactionService": "schema:interactionService", "dueForTime": "mv:dueForTime", "ownedBy": "mv:ownedBy", "operatedBy": "mv:operatedBy", "rights": "dct:rights", "about": { "@id": "schema:about", "@type": "@id" }, "description": { "@id": "schema:description", "@type": "xsd:string" }, "dateModified": { "@id": "schema:dateModified", "@type": "xsd:dateTime" }, "name": { "@id": "schema:name", "@container": "@set" }, "value": { "@id": "schema:value", "@type": "xsd:boolean" }, "postalCode": { "@id": "schema:postalCode", "@type": "xsd:string" }, "streetAddress": { "@id": "schema:streetAddress", "@type": "xsd:string" }, "country": { "@id": "schema:addressCountry", "@type": "xsd:string" }, "polygon": { "@id": "schema:polygon", "@type": "xsd:string" }, "latitude": { "@id": "schema:latitude", "@type": "xsd:double" }, "longitude": { "@id": "schema:longitude", "@type": "xsd:double" }, "openingHoursSpecification": { "@id": "schema:openingHoursSpecification", "@container": "@set" }, "contactType": { "@id": "schema:contactType", "@type": "xsd:string" }, "email": { "@id": "schema:email", "@type": "xsd:string" }, "telephone": { "@id": "schema:telephone", "@type": "xsd:string" }, "availableLanguage": { "@id": "schema:availableLanguage", "@container": "@set" }, "hoursAvailable": { "@id": "schema:hoursAvailable", "@container": "@set" }, "dayOfWeek": { "@id": "schema:dayOfWeek", "@type": "@id" }, "opens": { "@id": "schema:opens", "@type": "xsd:time" }, "closes": { "@id": "schema:closes", "@type": "xsd:time" }, "sectionName": { "@id": "schema:name", "@type": "xsd:string" }, "publicAccess": { "@id": "schema:publicAccess", "@type": "xsd:boolean" }, "priceSpecification": { "@id": "schema:priceSpecification", "@container": "@set" }, "price": { "@id": "schema:price", "@type": "xsd:double" }, "currency": { "@id": "schema:priceCurrency", "@type": "xsd:string" }, "amenityFeature": { "@id": "schema:amenityFeature", "@container": "@set" }, "photos": { "@id": "schema:photos", "@container": "@set" }, "entrance": { "@id": "mv:entrance", "@container": "@set" }, "exit": { "@id": "mv:exit", "@container": "@set" }, "numberOfLevels": { "@id": "mv:numberOfLevels", "@type": "xsd:integer" }, "totalCapacity": { "@id": "mv:totalCapacity", "@type": "xsd:integer" }, "liveCapacity": { "@id": "mv:capacity", "@type": "@id" }, "currentValue": { "@id": "mv:currentValue", "@type": "xsd:integer" }, "freeOfCharge": { "@id": "mv:freeOfCharge", "@type": "xsd:boolean" }, "timeStartValue": { "@id": "mv:timeStartValue", "@type": "xsd:double" }, "timeEndValue": { "@id": "mv:timeEndValue", "@type": "xsd:double" }, "timeUnit": { "@id": "mv:timeUnit", "@type": "xsd:string" }, "startDate": { "@id": "vp:startDate", "@type": "xsd:dateTime" }, "endDate": { "@id": "vp:endDate", "@type": "xsd:dateTime" }, "allows": { "@id": "vp:allows", "@container": "@set" }, "covered": { "@id": "vp:covered", "@type": "xsd:boolean" }, "maximumParkingDuration": { "@id": "vp:maximumParkingDuration", "@type": "xsd:duration" }, "openingHoursExtraInformation": { "@id": "vp:openingHoursExtraInformation", "@type": "xsd:string" }, "intendedAudience": { "@id": "vp:intendedAudience", "@type": "xsd:string" }, "restrictions": { "@id": "vp:restrictions", "@type": "xsd:string" }, "removalConditions": { "@id": "vp:removalConditions", "@type": "xsd:string" }, "postRemovalAction": { "@id": "vp:postRemovalAction", "@type": "xsd:string" }, "bicycleType": { "@id": "vp:bicycleType", "@type": "@id" }, "bicyclesAmount": { "@id": "vp:bicyclesAmount", "@type": "xsd:integer" }, "countingSystem": { "@id": "vp:countingSystem", "@type": "xsd:boolean" }, "companyName": { "@id": "gr:legalName", "@type": "xsd:string" }, "identifier": { "@id": "dct:identifier", "@type": "xsd:string" }, "date": { "@id": "dct:date", "@type": "xsd:dateTime" }, "closeTo": { "@id": "dbo:closeTo", "@container": "@set" }, "temporarilyClosed": { "@id": "vp:temporarilyClosed", "@type": "xsd:boolean" }, }, "@id": "https://data.velopark.be/data/De-Lijn_303749", "@type": "BicycleParkingStation", "dateModified": "2020-04-28T12:34:06.227Z", "identifier": "303749", "name": [{ "@value": " Meise Van Dievoetlaan", "@language": "nl" }], "temporarilyClosed": false, "ownedBy": { "@id": "https://www.delijn.be/", "@type": "BusinessEntity", "companyName": "De Lijn" }, "operatedBy": { "@id": "https://www.delijn.be/", "@type": "BusinessEntity", "companyName": "De Lijn" }, "address": { "@type": "PostalAddress", "postalCode": "1860", "streetAddress": "Nieuwelaan", "country": "Belgium", }, "hasMap": { "@type": "Map", "url": "https://www.openstreetmap.org/#map=18/50.94047/4.324813" }, "interactionService": { "@type": "WebSite", "url": "https://www.delijn.be/en/contact/" }, "@graph": [{ "@type": "https://data.velopark.be/openvelopark/terms#BicycleStand", "openingHoursSpecification": [{ "@type": "OpeningHoursSpecification", "dayOfWeek": "http://schema.org/Monday", "opens": "00:00", "closes": "23:59", }, { "@type": "OpeningHoursSpecification", "dayOfWeek": "http://schema.org/Tuesday", "opens": "00:00", "closes": "23:59", }, { "@type": "OpeningHoursSpecification", "dayOfWeek": "http://schema.org/Wednesday", "opens": "00:00", "closes": "23:59", }, { "@type": "OpeningHoursSpecification", "dayOfWeek": "http://schema.org/Thursday", "opens": "00:00", "closes": "23:59", }, { "@type": "OpeningHoursSpecification", "dayOfWeek": "http://schema.org/Friday", "opens": "00:00", "closes": "23:59", }, { "@type": "OpeningHoursSpecification", "dayOfWeek": "http://schema.org/Saturday", "opens": "00:00", "closes": "23:59", }, { "@type": "OpeningHoursSpecification", "dayOfWeek": "http://schema.org/Sunday", "opens": "00:00", "closes": "23:59", }], "maximumParkingDuration": "P30D", "publicAccess": true, "numberOfLevels": 1, "covered": false, "totalCapacity": 5, "allows": [{ "@type": "AllowedBicycle", "bicycleType": "https://data.velopark.be/openvelopark/terms#RegularBicycle", "bicyclesAmount": 5, "countingSystem": false, }], "geo": [{ "@type": "GeoCoordinates", "latitude": 50.94047, "longitude": 4.324813 }], "priceSpecification": [{ "@type": "PriceSpecification", "freeOfCharge": true }], "@id": "https://data.velopark.be/data/De-Lijn_303749#section1", }], } const compacted = await LinkedDataLoader.compact(veloparkEntry) expect(compacted.fee).equal("no") expect(compacted.operator).equal("De Lijn") expect(compacted.building).equal("bicycle_shed") expect(compacted.access).equal("yes") expect(compacted.max_stay).equal("30 days") expect(compacted.opening_hours).equal("24/7") }) })