[Application-profiles-ig] Python implementation(s)

Phil Barker phil.barker at pjjk.co.uk
Sat Dec 5 11:48:25 GMT 2020


Thanks for the pointers Tom. I found the csvschema branch of your csv2shex.py yesterday, and was working with it in the afternoon. As a python structure I like it, but I'm still swithering between this approach of class-properties and the alternative of just using dicts and lists. The main advantage I see in the latter is support from standard python libraries. For example getting a printout with pprint, converting to JSON with json.dumps(). It's possibly more flexible too, the value for TripleConstraints["valueConstraint"] could be a string or a list. Feel free to consider this flexibility as a weakness. The other weakness is having a rats nest of a dict of dicts of lists of dicts... On balance, I think it's worth exploring this option more, and will try to do so, but please do let me know what you think. Phil On 05/12/2020 08:52, Thomas Baker wrote: >On 2020-12-04 07:07, Phil Barker wrote:>>Tom, would you be interested in a chat about this?>>Perhaps, if it's not needed for more pressing work we>>could use the regular slot we have booked on Dec 16th.>>If anyone else wants join that would be great.>Good idea! I have marked my calendar and the time is>already reserved.>>>It would be useful to have a "bare-bones" AP class that>>defined a data structure for an application profile and>>had a robust method for reading the profile from a CSV.>I agree re: "bare-bones" and have abandoned my earlier,>more convoluted solution for the simpler [1]:>>@dataclass>class CSVTripleConstraint:>"""Instances hold TAP/CSV elements related to triple constraints.""">propertyID: str = " ">propertyLabel: str = "">mandatory: str = "">repeatable: str = "">valueNodeType: str = "">valueDataType: str = "">valueConstraint: str = "">valueConstraintType: str = "">valueShape: str = "">note: str = "">>@dataclass>类CSVShape:>"""Instances hold TAP/CSV row elements related to shapes.""">shapeID: str = "">shapeLabel: str = None>start: bool = False>tc_list: List[CSVTripleConstraint] = field(default_factory=list)>>@dataclass>class CSVSchema:>"""List of CSVShape instances""">csvshapes_list: List[CSVShape] = field(default_factory=list)>>I can't imagine anything more bare-bones - unless one>were to drop the CSVSchema class and build the list of>CSVShape objects as a simple Python list.>>A csvreader() function reads a CSV file and iterates>through the resulting rows (each one a dictionary),>instantiating a new CSVShape object whenever it>encounters a new shapeID [2]. I have added extensive>comments to the function to make it easier to read.>(Note that it does not yet support "shape on its own>line", but could.)>>>It might also be useful for it to have a simple print()>>function. This banana shouldn't come with a gorilla>>bringing a jungle[1]>(Nice reference - thanks!)>>The following command prints a given CSV to the screen>in a vertical format to show what it sees:>>$ csv2shex inspect example.csv>DCTAP>Shape>shapeID: :default>start: True>Triple Constraint>propertyID: dct:title>Triple Constraint>propertyID: dct:subject>Triple Constraint>propertyID: dct:date>>Another command simply shows the model:>>$ csv2shex model>DC Tabular Application Profile>Shape elements:>shapeID>shapeLabel>start>Triple constraint elements:>propertyID>propertyLabel>mandatory>repeatable>valueNodeType>valueDataType>valueConstraint>valueConstraintType>valueShape>note>>I have been working for awhile on a 'csvschema' branch,>which I recently set as the default branch on Github, but>I plan to soon rename 'csvschema' as 'main' and delete the>outdated, no-longer-default 'master' branch.>>Tom>>[1]https://github.com/tombaker/csv2shex/blob/csvschema/csv2shex/csvshape.py>[2]https://github.com/tombaker/csv2shex/blob/csvschema/csv2shex/csvreader.py>-- Phil Barker <http://people.pjjk.net/phil>.http://people.pjjk.net/philCETIS LLP <https://www.cetis.org.uk>: a cooperative consultancy for innovation in education technology. PJJK Limited <https://www.pjjk.co.uk>: technology to enhance learning; information systems for education. CETIS is a co-operative limited liability partnership, registered in England number OC399090 PJJK Limited is registered in Scotland as a private limited company, number SC569282. -------------- next part -------------- An HTML attachment was scrubbed... URL: <https://lists.www.voudr.com/pipermail/application-profiles-ig/attachments/20201205/fb205423/attachment.htm>


More information about the Application-profiles-ig mailing list