Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6 add schemaorg data to head of view page #15

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
66 changes: 65 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import uuid

import re
import json
import flask
import flask_moment
Expand Down Expand Up @@ -37,6 +38,58 @@ def load_data():
return {}




def create_json_ld(dataset):
data = load_data()
if dataset not in data:
return {}
json_ld_dict = {
"@context": "https://schema.org/",
"@type": "Dataset",
"name": data[dataset]['title'],
"description": re.sub("<.*>", "",data[dataset]['description']),
"url": f"https://data.aifarms.org/view/{ dataset }",
#"sameAs": "",
#"version": "",
"isAccessibleForFree": True,
"keywords": data[dataset].get('keywords', []),
"license": f"https://data.aifarms.org/license/{ dataset }",
#"identifier": {},
"citation": data[dataset]['citation'],
"creator": [],
#"provider": {
#"@id": "",
#"@type": "",
#"legalName": "",
#"name": "",
#"url": ""
#},
#"publisher": {
# "@id": ""
#}
}
for i in range(len(data[dataset]['authors'])):
json_ld_dict['creator'].append( {
#"@id": "",
"@type": "Role",
"roleName": "Author",
"creator": {
#"@id": "",
"@type": "Person",
"name": data[dataset]['authors'][i]
}
})

return json_ld_dict


def makelist(obj):
if isinstance(obj, set):
return list(obj)
raise TypeError


@app.get("/")
def home():
data = load_data()
Expand All @@ -48,6 +101,7 @@ def home():
}
return flask.render_template("index.html", **kwargs)


def render_template(template, dataset):
data = load_data()
if dataset not in data:
Expand All @@ -59,14 +113,24 @@ def render_template(template, dataset):
filesize = "N/A"
keywords = set(["AIFARMS"])
keywords.update(data[dataset].get("keywords", ""))
return flask.render_template(template, dataset=dataset, filesize=filesize, aifarms_keywords=keywords, **data[dataset])
json_ld_string = json.dumps(create_json_ld(dataset), default=makelist)
return flask.render_template(template, dataset=dataset, filesize=filesize, aifarms_keywords=keywords, **data[dataset], json_ld_string=json_ld_string)


@app.get("/view/<dataset>")
def view_dataset(dataset):
return render_template("view.html", dataset=dataset)


@app.get("/ld/<dataset>")
def view_json_ld(dataset):
data = load_data()
if dataset not in data:
return flask.redirect('/')
json_ld_string = json.dumps(create_json_ld(dataset), default=makelist)
return flask.Response(json_ld_string, mimetype='application/ld+json')


@app.get("/croissant/<dataset>")
def croissant_dataset(dataset):
return render_template("croissant.json", dataset=dataset)
Expand Down
4 changes: 2 additions & 2 deletions data/datasets.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"email": "[email protected]"
},
"citation": "",
"keywords":["pigs"],
"keywords": ["pigs"],
"funding": "This work is supported by Agriculture and Food Research Initiative (AFRI) grant no. 2020-67021-32799/project accession no.1024178 from the USDA National Institute of Food and Agriculture.",
"license": "NON-EXCLUSIVE RESEARCH USE LICENSE\nFOR {{ title }} DATA\n\nThe Data (as defined below) will only be licensed to You (as defined below) upon the condition that You accept all of the terms and conditions contained in this license agreement (“License”). Please read this License carefully. By downloading and using the Data, You accept the terms and conditions of this License.\n\nDefinitions.\n\n1.1.\t“Commercial Use” means sale, lease, license, distribution or otherwise making the Data available to a third party.\n1.2.\t“Data” means the {{ short_description }}”.\n1.3.\t“Research Use” means use of the Data for Your non-profit research, development, academic, educational or personal and individual use, and expressly excludes Commercial Use.\n1.4.\t“You” (or “Your”) means an individual or legal entity exercising rights under, and complying with all of the terms of, this License. For an individual, “You” includes your personal use of the Data only. For a legal entity, “You” includes all entities under common control with the entity and all employees of the entity. For purposes of this License, “common control” means right to control, or actual control of, the management of such other entity, whether by ownership of securities, voting rights, management authority, agreement, or otherwise.\n\n2.\tLicense Grant and Restrictions.\nSubject to Your compliance with the terms and conditions of this License:\n2.1.\tLicense Grant: The Board of Trustees of the University of Illinois (“ILLINOIS”), on behalf of the [insert department name], grants You a non-exclusive, non-transferable, restricted license to:\n2.1.1.\tUse the Data for Your Research Use; and\n2.2.\tYou acknowledge the Data is owned by ILLINOIS, and ILLINOIS retains all right, title, and interest in and to the Data.\n2.3.\tNothing in this License shall be construed as conferring any license under any of ILLINOIS’ or any third party’s intellectual property rights, whether by estoppel, implication, or otherwise.\n2.4.\tFor any reports or published results obtained using the Data, You shall acknowledge use of the Data by the following citation: “The {{ title }} Data, used by [insert Your name], was developed by [insert department] at the University of Illinois Urbana-Champaign.”\n2.5 Restrictions:\n2.5.1\tYou shall not create any modifications, enhancements, upgrades, or improvements to the Data.\n2.5.2 You shall not use the Data for Commercial Use\n2.5.3\tYou shall not share the Data with any other person or entity.\n\n3.\tConfidential Information.\n3.1.\tYou acknowledge that the Data is proprietary to ILLINOIS. You agree to protect the Data from disclosure or unauthorized use and to treat the Data with at least the same level of care as You use to protect Your own proprietary Data and/or confidential information, but in no event no less than a reasonable standard of care.\n3.2.\tIf You become aware of any unauthorized licensing, copying, or use of the Data, You shall promptly notify ILLINOIS in writing at [email protected].\n3.3.\tYou agree to use the Data only in the manner and for the specific uses authorized in this License.\n\n4.\tFeedback.\n4.1.\tBecause the Data is provided to You free of charge pursuant to this License, ILLINOIS encourages You to provide feedback on the Data. ILLINOIS also encourages You to provide information regarding your experience with using the Data for your research. Please submit such feedback to {{ contact }}.\n4.2.\tBy contributing your feedback, You agree that such feedback may be used by ILLINOIS for any purpose.\n\n5.\tLimitation of Warranties.\n5.1.\tEXCEPT AS SET FORTH IN THIS LICENSE, TO THE FULLEST EXTENT ALLOWED BY APPLICABLE LAW, THE DATA IS PROVIDED “AS IS,” AND ILLINOIS DISCLAIMS ALL EXPRESS AND IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT OF ANY PATENT, COPYRIGHT, TRADEMARK OR OTHER RIGHTS OF THIRD PARTIES IN CONNECTION WITH THE USE OF THE DATA BY ANY PERSON OR ENTITY.\n5.2.\tTHIS LIMITATION OF WARRANTY IS AN ESSENTIAL PART OF THIS LICENSE. NO USE OF THE DATA IS AUTHORIZED EXCEPT UNDER THIS DISCLAIMER.\n5.3.\tANY DATA DOWNLOADED IS AT YOUR OWN DISCRETION AND RISK, AND YOU ARE SOLELY RESPONSIBLE FOR ANY DAMAGE TO YOUR COMPUTER SYSTEM OR LOSS OF DATA THAT RESULTS FROM THE DOWNLOAD OF SUCH DATA, INCLUDING ANY DAMAGES RESULTING FROM COMPUTER VIRUSES.\n\n6.\tIndemnification.\nYou shall indemnify, defend, and hold harmless ILLINOIS (including its trustees, fellows, officers, employees, students, and agents) against any and all claims, losses, damages, and/or liability of whatsoever nature, as well as costs and expenses (including reasonable attorneys’ fees) arising out of or related to Your use, or inability to use, the Data, regardless of theory of liability, whether for breach or in tort (including negligence).\n\n7.\tLimitation of Liability.\n7.1.\tYou assume the entire risk as to the quality, results, performance, and/or non-performance of the Data. Should the Data prove defective in any manner, You assume the entire cost of any necessary, servicing, repair or correction.\n7.2.\tIn no event shall ILLINOIS (including its trustees, fellows, officers, employees, students, and agents) be responsible or liable for any direct, indirect, special, incidental, punitive, consequential or other damages whatsoever (including lost profits, business, revenue, use, data, or other economic advantage) in connection with, or arising out of, or related to this License, regardless of the theory of liability, whether for breach or in tort (including negligence), even if ILLINOIS may have been previously advised of the possibility of such damage.\n7.3.\tLiability for damages shall be limited and excluded as set forth in this Section, even if any remedy provided for in this License fails of its essential purpose.\n\n8.\tTermination.\n8.1.\tThe term of this License shall be 5 years from the Effective Date, unless earlier terminated as provided herein.\n8.2.\tYou may terminate this License at any time by destroying all copies of the Data.\n8.3.\tThis License, and the rights granted hereunder, will terminate automatically, and without any further notice from or action by ILLINOIS, if You fail to comply with any obligation of this License.\n8.4.\tUpon termination, You must immediately cease use of and destroy all copies of the Data and verify such destruction in writing to ILLINOIS.\n8.5.\tAll provisions of this License that by their nature contemplate rights and obligations of the parties to be enjoyed or performed after the termination of the License will survive termination of all, or any part of the License, including the following: Sections 3, 5, 6, 7, 9, and 10.\n\n9.\tExport Controls.\nThe Data delivered under this License may be subject to U.S. export control laws and may be subject to export or import regulations in other countries. You agree to comply strictly with all such applicable laws and regulations and acknowledge that You have the responsibility, at Your own expense, to obtain such licenses to export, re-export, or import as may be required.\n\n10.\tMiscellaneous.\n10.1.\tGoverning Law. This License shall be governed by the laws of the State of Illinois, U.S.A., without regard to any conflict of laws provisions.\n10.2.\tSeverability. If any provision(s) of this License are held to be invalid, illegal, or unenforceable by a court of competent jurisdiction, such invalidity or unenforceability shall not in any way affect the validity or enforceability of the remaining provisions.\n10.3.\tAssignment. You may not assign or otherwise transfer any of Your rights or obligations under this License, without the prior written consent of ILLINOIS.\n10.4.\tEntire Agreement. This License represents the parties’ entire agreement relating to the Data. Except as otherwise provided herein, no modification of this License is binding unless in writing and signed by an authorized representative of each party.\n10.5.\tWaiver. The failure of either party to enforce any provision of this License shall not constitute a waiver of that right or future enforcement of that or any other provision. The waiver of a breach or default of this License may be effected only in writing by the waiving party.\n\nApproved for legal form, Office of University Counsel, JC 10/2023\n"
},
Expand All @@ -44,7 +44,7 @@
"name": "Jose Cuaran"
},
"citation": "",
"keywords":[],
"keywords": [],
"funding": "This work is supported by National Institute of Food and Agriculture grant no. 2020-67021- 32799",
"license": "N/A"
}
Expand Down
5 changes: 5 additions & 0 deletions templates/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

{% block head %}
<link href="static/css/carousel.css" rel="stylesheet">

<script type="application/ld+json">
{{ json_ld_string|safe }}
</script>

{% endblock %}

{% block main %}
Expand Down
Loading