Rdflib and activitystreams - json-ld
so I'm investigating rdflib to use with ActivityStreams. My current main goal is to input an Object and get the same one back!
My current try looks like this
import rdflib
G = rdflib.Graph()
G.parse('https://raw.githubusercontent.com/HelgeKrueger/bovine/main/tests/data/mastodon_announce_1_undo.json', format='json-ld')
print(G.serialize(format='json-ld',
auto_compact=False,
use_native_types=True,
context="https://www.w3.org/ns/activitystreams",
base="https://my_domain/activitypub/user/3c0281b7-bede-460a-a49b-3b6d7d4eb32f/activity"))
and gets the output
{
"#context": "https://www.w3.org/ns/activitystreams",
"#graph": [
{
"actor": "https://first_domain/users/first",
"id": "https://first_domain/users/first/statuses/1097854/activity/undo",
"object": "https://first_domain/users/first/statuses/1097854/activity",
"to": "as:Public",
"type": "Undo"
},
{
"actor": "https://first_domain/users/john",
"cc": [
"https://first_domain/users/john/followers",
"https://second_domain/users/second"
],
"id": "https://first_domain/users/first/statuses/1097854/activity",
"object": "https://second_domain/users/second/statuses/109724234853",
"published": "2023-01-31T19:11:46+00:00",
"to": "as:Public",
"type": "Announce"
}
]
}
The signature is missing, because it's not part of the namespace -> This is as desired.
Unfortunately, there is the #graph property and the "Announce" is not represented as a subobject of
{
"actor": "https://first_domain/users/first",
"id": "https://first_domain/users/first/statuses/1097854/activity/undo",
"object": "https://first_domain/users/first/statuses/1097854/activity",
"to": "as:Public",
"type": "Undo"
}
Is there a way to get rdflib to ouput it like:
{
"#context": "https://www.w3.org/ns/activitystreams",
"actor": "https://first_domain/users/first",
"id": "https://first_domain/users/first/statuses/1097854/activity/undo",
"object": {
"actor": "https://first_domain/users/john",
"cc": [
"https://first_domain/users/john/followers",
"https://second_domain/users/second"
],
"id": "https://first_domain/users/first/statuses/1097854/activity",
"object": "https://second_domain/users/second/statuses/109724234853",
"published": "2023-01-31T19:11:46+00:00",
"to": "as:Public",
"type": "Announce"
},
"to": "as:Public",
"type": "Undo"
}
Thanks!
Related
Vega Chloropleth Map Visualisation
For some reason vega is reading my data as 0 when the numbers range from 1-234. I am attempting to show a visualisation of a chloropleth map of crypto-ownership by country. The countries have been ranked 1-234 and that is meant to show on the tooltip however, this is being shown as 0 on the tooltip. How do I fix this. Here is my code: { "$schema": "https://vega.github.io/schema/vega-lite/v5.json", "title":{ "text": "Crypto Ownership Worldwide", "subtitle": "Source: FILL", "anchor": "start" }, "width":500, "height":400, "data": { "url": "https://raw.githubusercontent.com/tomiwav/tomiwav.github.io/main/custom.geo%20(3).json", "format":{"property": "features"} }, "projection":{"type": "mercator"}, "transform": [ { "lookup":"properties.name", "from":{ "key": "Country", "fields": ["Rank"], "data":{ "url": "https://raw.githubusercontent.com/tomiwav/tomiwav.github.io/main/datarank.csv", "format":{"type":"csv"} } } } ], "mark":{ "type": "geoshape", "fill":"lightgray", "stroke":"black", "strokeWidth":0.5 }, "encoding": { "color": { "field": "Rank", "type": "quantitative", "scale": { "domain":[234,1], "scheme": "oranges" } }, "tooltip":[ {"field":"properties.name", "title":"Country"}, {"field":"Rank","type":"quantitative","title":"Number of Crypto Owners","format":".2f"} ] }, "config": {"mark": {"invalid": null} } }
Your lookup was failing. You need a lower case "c" on country. { "$schema": "https://vega.github.io/schema/vega-lite/v5.json", "title": { "text": "Crypto Ownership Worldwide", "subtitle": "Source: FILL", "anchor": "start" }, "width": 500, "height": 400, "data": { "url": "https://raw.githubusercontent.com/tomiwav/tomiwav.github.io/main/custom.geo%20(3).json", "format": {"property": "features"} }, "projection": {"type": "mercator"}, "transform": [ { "lookup": "properties.name", "from": { "key": "country", "fields": ["Rank"], "data": { "url": "https://raw.githubusercontent.com/tomiwav/tomiwav.github.io/main/datarank.csv", "format": {"type": "csv"} } } } ], "mark": { "type": "geoshape", "fill": "lightgray", "stroke": "black", "strokeWidth": 0.5 }, "encoding": { "color": { "field": "Rank", "type": "quantitative", "scale": {"domain": [234, 1], "scheme": "oranges"} }, "tooltip": [ {"field": "properties.name", "title": "Country"}, { "field": "Rank", "type": "quantitative", "title": "Number of Crypto Owners", "format": ".2f" } ] }, "config": {"mark": {"invalid": null}} }
Parse this Json array and extract the value of text
Here is the full json that I want to parse and extract the text that has the value: The product is in second line 3rd row. Can someone help? "activities": [ { "type": "message", "id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "timestamp": "2019-07-01T15:18:56.8251462Z", "serviceUrl": "XXXXXXXXXXXXXXXXXXXXXXXXX", "channelId": "directline", "from": { "id": "user1" }, "conversation": { "id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX" }, "text": "the milk" }, { "type": "message", "id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "timestamp": "2019-07-01T15:18:57.6856172Z", "localTimestamp": "2019-07-01T15:18:57.5099359+00:00", "channelId": "directline", "from": { "id": "XXXXXX", "name": "XXXXXX" }, "conversation": { "id": "XXXXXXXXXXXXXXXXXX" }, "text": "The product is in second line 3rd row", "attachments": [], "entities": [], "replyToId": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX" } ], "watermark": "1" }
You have specified that this is a full json you have placed in the question, But it is not full json you are missing something. "activities": [ //json array start from here { "type": "message", "id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "timestamp": "2019-07-01T15:18:56.8251462Z", "serviceUrl": "XXXXXXXXXXXXXXXXXXXXXXXXX", "channelId": "directline", "from": { "id": "user1" }, "conversation": { "id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX" }, "text": "the milk" }, { "type": "message", "id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "timestamp": "2019-07-01T15:18:57.6856172Z", "localTimestamp": "2019-07-01T15:18:57.5099359+00:00", "channelId": "directline", "from": { "id": "XXXXXX", "name": "XXXXXX" }, "conversation": { "id": "XXXXXXXXXXXXXXXXXX" }, "text": "The product is in second line 3rd row", "attachments": [], "entities": [], "replyToId": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX" } ], //json array ends here these are extra lines ***"watermark": "1" }*** if you want to use this array you need to add a '{' in very top line before "activities": [ I am placing here a valid json now you can check it on Json parser used to parse json in objects *Valid Json Here : * { "activities": [ { "type": "message", "id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "timestamp": "2019-07-01T15:18:56.8251462Z", "serviceUrl": "XXXXXXXXXXXXXXXXXXXXXXXXX", "channelId": "directline", "from": { "id": "user1" }, "conversation": { "id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX" }, "text": "the milk" }, { "type": "message", "id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "timestamp": "2019-07-01T15:18:57.6856172Z", "localTimestamp": "2019-07-01T15:18:57.5099359+00:00", "channelId": "directline", "from": { "id": "XXXXXX", "name": "XXXXXX" }, "conversation": { "id": "XXXXXXXXXXXXXXXXXX" }, "text": "The product is in second line 3rd row", "attachments": [], "entities": [], "replyToId": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX" } ], "watermark": "1" }
Json schema for array of objects doesn't validate
I have this schema for a json response { "title": "Products", "description": "schema for products", "type": "array", "properties": { "id": { "description": "id of a product", "type": "integer" }, "name": { "description": "name of the product", "type": "string" }, "created_at": { "description": "record created_at", "type": "string", "format": "date-time" }, "updated_at": { "description": "record updated_at", "type": "string", "format": "date-time" } }, "required": ["id", "name"] } and I want to match this schema with this json [{ "id": 1, "name": "Cricket Ball" }, { "id": 2, "name": "Soccer Ball" }, { "id": 3, "name": "football ball" }, { "id": 4, "name": "Basketball ball" }, { "id": 5, "name": "Table Tennis ball" }, { "id": 6, "name": "Tennis ball" }] This schema matches the response but it also matches the schema in which the required field is this "required": ["ids", "names"] I think the schema is validated against the array and the objects in the array are not validated.
The way you have it set up now, your properties key refers to the array itself, not to each item, and is being ignored (because arrays don't have properties, they just have items). You need to use the items key to validate each item in the array, like so: { "title": "Products", "description": "schema for products", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "id of a product", "type": "integer" }, "name": { "description": "name of the product", "type": "string" }, "created_at": { "description": "record created_at", "type": "string", "format": "date-time" }, "updated_at": { "description": "record updated_at", "type": "string", "format": "date-time" } }, "required": ["id", "name"] } }
try map new_array = response.map{ |k| { 'id': k['properties']['id']['description'], 'name': k['properties']['name']['description'] } }
How to define the min size of array in the json schema
I want to make a schema of json file.It's for an array of products. The json schema is similar as below: { "$schema": "http://json-schema.org/draft-04/schema#", "title": "Product set", "type": "array", "items": { "title": "Product", "type": "object", "properties": { "id": { "description": "The unique identifier for a product", "type": "number" }, "name": { "type": "string" }, "price": { "type": "number", "minimum": 0, "exclusiveMinimum": true }, "tags": { "type": "array", "items": { "type": "string" }, "minItems": 1, "uniqueItems": true }, "dimensions": { "type": "object", "properties": { "length": {"type": "number"}, "width": {"type": "number"}, "height": {"type": "number"} }, "required": ["length", "width", "height"] }, "warehouseLocation": { "description": "Coordinates of the warehouse with the product", "$ref": "http://json-schema.org/geo" } }, "required": ["id", "name", "price"] } } The array should at least one item in it. How can I define the minimum of the array? Do I need to add the minimun defination?
To set the minimum # of item in an array, use the "minItems". See: https://datatracker.ietf.org/doc/html/draft-fge-json-schema-validation-00#section-5.3.3 and http://jsonary.com/documentation/json-schema/?section=keywords/Array%20validation { "$schema": "http://json-schema.org/draft-04/schema#", "title": "Product", "description": "A product from Acme's catalog", "type": "object", "properties": { ... "tags": { "type": "array", "items": { "type": "string" }, "minItems": 1, "maxItems": 4, "uniqueItems": true } }, "required": ["id", "name", "price"] }
It looks like draft v4 permits what you are looking for. From http://json-schema.org/example1.html: { "$schema": "http://json-schema.org/draft-04/schema#", "title": "Product", "description": "A product from Acme's catalog", "type": "object", "properties": { ... "tags": { "type": "array", "items": { "type": "string" }, "minItems": 1, "uniqueItems": true } }, "required": ["id", "name", "price"] } Notice that the "tags" property is defined as an array, with a minimum number of items (1).
I suppose no, at least looking to working draft the minimum is applied only for numeric values, not arrays. 5.1. Validation keywords for numeric instances (number and integer) ... 5.1.3. minimum and exclusiveMinimum So you should be good with min/maxItems for arrays.
what is wrong with this json array code facebook form
The error i am getting is this : Can't parse fields attribute. Is it a JSON array or CSV list? The problem is in the select menu which is being included in the form. what i want to achieve is a select box as shown here on this link : Registration plugin But somehow the problem is that the select box is not being displayed! <iframe src='http://www.facebook.com/plugins/registration.php? client_id=325340244194060& redirect_uri=http://www.pingcampus.com/facebook_registration_plugin/store_user_data.php& fields=[ {"name":"name"}, {"name":"email"}, {"name":"gender"}, {"name":"birthday"}, {'name':'captain', 'description':'Best Captain', 'type':'select', 'options':{'P':'Jean-Luc Picard','K':'James T. Kirk'}} {'name':'captain', 'description':'College','type':'select','options': {'P':'Jean-Luc Picard','K':'James T. Kirk', '1':'Acropolis','2':'Astral','3':'Aurobindo','4':'BM','5':'Central','6':'Chameli','7':'IET (DAVV)','8':'IIST ','9':'IIST2 ','10':'IPS ','11':'JDCT ','12':'KCB ','13':'LKCT ','14':'LNCT ','15':'MIT (Malwa) ','16':'Malwa (Malwa2) ','17':'Mandsaur ','18':'Mathuradevi ','19':'MITM (Medi1) ','20':'MIST (Medi2) ','21':'MGIEM ','22':'Nalin ','23':'Oriental ','24':'Patel ','25':'Prestige ','26':'Priyatam ','27':'Rishiraj ','28':'RKDF ','29':'Royal ','30':'Sanghvi ','31':'Sdbansal ','32':'SGSITS ','33':'SIMS ','34':'SKSITS ','35':'Star ','36':'SVCE ','37':'SVITS ','38':'Transnational ','39':'Truba ','40':'Venkateshwar ','41':'Vidhyasagar ','42':'Vikrant ','43':'Vindhya ','#':'-------------------------------- ','#':'Commerce ','#':'-------------------------------- ','44':'Acro ','45':'Apex ','46':'Arihant ','47':'BM ','48':'Chamelidevi ','49':'Chimc ','50':'Choithram ','51':'Christian ','52':'DCBS (Daly College) ','53':'IBMR ','54':'IIMR (IIST) ','55':'IIPS (DAVV) ','56':'Ilva ','57':'IMIR ','58':'Imperial ','59':'IMS (DAVV) ','60':'Islamia ','61':'JDCT ','62':'LKCT ','63':'LNCT ','64':'Maharaja ','65':'MIT (Malwa) ','66':'Mathuradevi ','67':'Matushri ','68':'MBKhalsa ','69':'Medicaps ','70':'Patel ','71':'Pioneer ','72':'Prestige ','73':'Priyatam ','74':'Renaissance ','75':'Rishiraj ','76':'Sahib ','77':'SAIMS ','78':'Sanghvi Innovative ','79':'Sapient ','80':'SGSITS ','81':'SIMS ','82':'SJDM ','83':'SKSITS ','84':'Softvision ','85':'SVCE ','86':'Rransnational ','87':'Vaishnav ','88':'Venkteshwar ','89':'Vidhyasagar ','90':'Vikrant ','#':'-------------------------------- ','#':'Pharmacy ','#':'-------------------------------- ','91':'Acropolis ','92':'Aurobindo ','93':'BM ','94':'Central ','95':'SOPE (DAVV) ','96':'IIP(IIST) ','97':'IPS ','98':'Oriental ','99':'Rishiraj ','100':'RKDF ','101':'Safe ','102':'SGSITS ','103':'Smriti (SCOPE) ','104':'svce ','105':'vikrant ','#':'-------------------------------- ','#':'Medical ','#':'-------------------------------- ','106':'Arihant ','107':'Bombay Hospital ','108':'Index ','109':'MGMMC ','110':'RD Memorial ','111':'Shubhdeep ','#':'-------------------------------- ','#':'Dental ','#':'-------------------------------- ','112':'Aurobindo ','113':'CDSH ','114':'GCD ','115':'Index ','116':'Modern ','#':'-------------------------------- ','#':'Arts ','#':'-------------------------------- ','117':'BIG Aims ','118':'Frameboxx ','119':'INIFD ','120':'MAAC ','121':'SDPS ','122':'SJMC (DAVV) ','123':'Virtual Voyage ','124':'Zica ','132':'EMRC (DAVV) ','#':'-------------------------------- ','#':'Architecture ','#':'-------------------------------- ','125':'IPS ','126':'SDPS ','#':'-------------------------------- ','#':'Law ','#':'-------------------------------- ','127':'Christian ','128':'SOL(DAVV) ','129':'IIL ','130':'Vaishnav'} }, {"name":"Arts","description":"Arts","type":"checkbox","value":"Arts"}, {"name":"Act","description":"Act","type":"checkbox","value":"Act"}, {"name":"Cooking","description":"Cooking","type":"checkbox","value":"Cooking"}, {"name":"Dance","description":"Dance","type":"checkbox","value":"Dance"}, {"name":"Designing","description":"Designing","type":"checkbox","value":"Designing"}, {"name":"Fashion","description":"Fashion Designing","type":"checkbox","value":"Fashion Designing"}, {"name":"Interior","description":"Interior Designing","type":"checkbox","value":"Interior Designing"}, {"name":"Modeling","description":"Modeling","type":"checkbox","value":"Modeling"}, {"name":"Photography","description":"Photography","type":"checkbox","value":"Photography"}, {"name":"Poetry","description":"Poetry / Writing","type":"checkbox","value":"Poetry / Writing"}, {"name":"Programming","description":"Programming","type":"checkbox","value":"Programming"}, {"name":"Reading","description":"Reading","type":"checkbox","value":"Reading"}, {"name":"Sketching","description":"Sketching / Drawing","type":"checkbox","value":"Sketching / Drawing"}, {"name":"Singing","description":"Singing","type":"checkbox","value":"Singing"}, {"name":"Sports","description":"Sports","type":"checkbox","value":"Sports"}, {"name":"Stunting","description":"Stunting","type":"checkbox","value":"Stunting"}, {"name":"Videography","description":"Checkthis","type":"checkbox","value":"Videography"}, {"name":"Other","description":"Other","type":"checkbox","value":"Other"}, {"name":"captcha"} ]' scrolling="auto" frameborder="no" style="border:none" allowTransparency="true" width="500" height="800" > </iframe>
Try to replace fields=[....] with valid JSON [ { "name": "name" }, { "name": "email" }, { "name": "gender" }, { "name": "birthday" }, { "name": "captain", "description": "BestCaptain", "type": "select", "options": { "P": "Jean-LucPicard", "K": "JamesT.Kirk" } }, { "name": "captain", "description": "College", "type": "select", "options": { "1": "Acropolis", "2": "Astral", "3": "Aurobindo", "4": "BM", "5": "Central", "6": "Chameli", "7": "IET(DAVV)", "8": "IIST", "9": "IIST2", "10": "IPS", "11": "JDCT", "12": "KCB", "13": "LKCT", "14": "LNCT", "15": "MIT(Malwa)", "16": "Malwa(Malwa2)", "17": "Mandsaur", "18": "Mathuradevi", "19": "MITM(Medi1)", "20": "MIST(Medi2)", "21": "MGIEM", "22": "Nalin", "23": "Oriental", "24": "Patel", "25": "Prestige", "26": "Priyatam", "27": "Rishiraj", "28": "RKDF", "29": "Royal", "30": "Sanghvi", "31": "Sdbansal", "32": "SGSITS", "33": "SIMS", "34": "SKSITS", "35": "Star", "36": "SVCE", "37": "SVITS", "38": "Transnational", "39": "Truba", "40": "Venkateshwar", "41": "Vidhyasagar", "42": "Vikrant", "43": "Vindhya", "44": "Acro", "45": "Apex", "46": "Arihant", "47": "BM", "48": "Chamelidevi", "49": "Chimc", "50": "Choithram", "51": "Christian", "52": "DCBS(DalyCollege)", "53": "IBMR", "54": "IIMR(IIST)", "55": "IIPS(DAVV)", "56": "Ilva", "57": "IMIR", "58": "Imperial", "59": "IMS(DAVV)", "60": "Islamia", "61": "JDCT", "62": "LKCT", "63": "LNCT", "64": "Maharaja", "65": "MIT(Malwa)", "66": "Mathuradevi", "67": "Matushri", "68": "MBKhalsa", "69": "Medicaps", "70": "Patel", "71": "Pioneer", "72": "Prestige", "73": "Priyatam", "74": "Renaissance", "75": "Rishiraj", "76": "Sahib", "77": "SAIMS", "78": "SanghviInnovative", "79": "Sapient", "80": "SGSITS", "81": "SIMS", "82": "SJDM", "83": "SKSITS", "84": "Softvision", "85": "SVCE", "86": "Rransnational", "87": "Vaishnav", "88": "Venkteshwar", "89": "Vidhyasagar", "90": "Vikrant", "91": "Acropolis", "92": "Aurobindo", "93": "BM", "94": "Central", "95": "SOPE(DAVV)", "96": "IIP(IIST)", "97": "IPS", "98": "Oriental", "99": "Rishiraj", "100": "RKDF", "101": "Safe", "102": "SGSITS", "103": "Smriti(SCOPE)", "104": "svce", "105": "vikrant", "106": "Arihant", "107": "BombayHospital", "108": "Index", "109": "MGMMC", "110": "RDMemorial", "111": "Shubhdeep", "112": "Aurobindo", "113": "CDSH", "114": "GCD", "115": "Index", "116": "Modern", "117": "BIGAims", "118": "Frameboxx", "119": "INIFD", "120": "MAAC", "121": "SDPS", "122": "SJMC(DAVV)", "123": "VirtualVoyage", "124": "Zica", "125": "IPS", "126": "SDPS", "127": "Christian", "128": "SOL(DAVV)", "129": "IIL", "130": "Vaishnav", "132": "EMRC(DAVV)", "P": "Jean-LucPicard", "K": "JamesT.Kirk", "#": "--------------------------------" } }, { "name": "Arts", "description": "Arts", "type": "checkbox", "value": "Arts" }, { "name": "Act", "description": "Act", "type": "checkbox", "value": "Act" }, { "name": "Cooking", "description": "Cooking", "type": "checkbox", "value": "Cooking" }, { "name": "Dance", "description": "Dance", "type": "checkbox", "value": "Dance" }, { "name": "Designing", "description": "Designing", "type": "checkbox", "value": "Designing" }, { "name": "Fashion", "description": "Fashion Designing", "type": "checkbox", "value": "Fashion Designing" }, { "name": "Interior", "description": "Interior Designing", "type": "checkbox", "value": "Interior Designing" }, { "name": "Modeling", "description": "Modeling", "type": "checkbox", "value": "Modeling" }, { "name": "Photography", "description": "Photography", "type": "checkbox", "value": "Photography" }, { "name": "Poetry", "description": "Poetry / Writing", "type": "checkbox", "value": "Poetry / Writing" }, { "name": "Programming", "description": "Programming", "type": "checkbox", "value": "Programming" }, { "name": "Reading", "description": "Reading", "type": "checkbox", "value": "Reading" }, { "name": "Sketching", "description": "Sketching / Drawing", "type": "checkbox", "value": "Sketching / Drawing" }, { "name": "Singing", "description": "Singing", "type": "checkbox", "value": "Singing" }, { "name": "Sports", "description": "Sports", "type": "checkbox", "value": "Sports" }, { "name": "Stunting", "description": "Stunting", "type": "checkbox", "value": "Stunting" }, { "name": "Videography", "description": "Checkthis", "type": "checkbox", "value": "Videography" }, { "name": "Other", "description": "Other", "type": "checkbox", "value": "Other" }, { "name": "captcha" } ]
Your fields parameter for Registration social plugin contain not valid JSON object (JSON should use double quotes instead of single quotes) and you're missing , (comma) in the middle of array, after next line: {'name':'captain', 'description':'Best Captain', 'type':'select', 'options':{'P':'Jean-Luc Picard','K':'James T. Kirk'}} Update: Actually even usage of just valid JSON may not work in that case due to fact that this is passed as query string arguments, so that JSON should be properly encoded to avoid problems. Also may cause some issues. Also you have two fields named "captain" (which cause problem with registration plugin too). Here I've created some samples (due to massive code of fields, I'm not putting them here): Creating fields from JavaScript object and passing em to Registration plugin: http://jsfiddle.net/QwdCv/ Correctly encoded fields in URL passed directly within iframe tag src attribute: http://jsfiddle.net/QwdCv/1/