-
Notifications
You must be signed in to change notification settings - Fork 1
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
Schema.regen.network browser & RDFS Ontology POC #54
Open
clevinson
wants to merge
9
commits into
main
Choose a base branch
from
clev/schema-www
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
558f1d8
first commit for schema reference site
clevinson 1e5c7d4
remove specific credit-classes.tt. file
clevinson f5514d8
refactor to functions as components, remove @apply css usage
clevinson b9c78c9
add ResourceList component to PropertyView
clevinson c3d4c6b
update views
clevinson a77515e
migrate to app router
clevinson 6316ef9
clean up tailwind config
clevinson 7a65b03
cleanup conditional rendering
clevinson 0297802
Update schema-www/src/app/[item]/page.tsx
clevinson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . | ||
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . | ||
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . | ||
@prefix regen: <http://schema.regen.network#> . | ||
@prefix schema: <http://schema.org/> . | ||
|
||
regen:CreditClass a rdfs:Class ; | ||
rdfs:comment "A class of credits that can be issued for a project. Each credit class has specific methodologies and rules for issuing credits." ; | ||
rdfs:label "Credit Class" ; | ||
. | ||
|
||
regen:offsetGenerationMethod a rdf:Property ; | ||
rdfs:label "Offset Generation Method" ; | ||
rdfs:domain regen:CreditClass ; | ||
rdfs:range xsd:string ; | ||
rdfs:comment "In the case where a credit represents an offset, offset generation method represents the mechanicsm by which the credit is to be counted as an offset (e.g. Avoided Emissions, Carbon Sequestration)" ; | ||
. | ||
|
||
regen:coBenefits a rdf:Property ; | ||
rdfs:label "Co-Benefits" ; | ||
rdfs:domain regen:CreditClass ; | ||
rdfs:range schema:ItemList; | ||
rdfs:comment "A list of co-benefits expected to be available for projects under a given Credit Class." | ||
. | ||
|
||
regen:approvedMethodologies a rdf:Property ; | ||
rdfs:label "Approved Methodologies" ; | ||
rdfs:domain regen:CreditClass ; | ||
rdfs:range schema:ItemList; | ||
rdfs:comment "A list of versioned methodologies that are approved for a given Credit Class, or a specific project. List Items are all of the type 'Methodology Version'"; | ||
. | ||
|
||
regen:Project a rdfs:Class ; | ||
rdfs:comment "" ; | ||
rdfs:label "Project" ; | ||
. | ||
|
||
regen:additionalCertification a rdf:Property ; | ||
rdfs:label "Additional Certification" ; | ||
rdfs:domain regen:Project ; | ||
rdfs:range regen:CertificationProtocol; | ||
rdfs:comment "An optional additional certification for a given project."; | ||
. | ||
|
||
schema:name a rdf:Property ; | ||
rdfs:label "Name" ; | ||
rdfs:domain regen:Project ; | ||
rdfs:range xsd:string; | ||
rdfs:comment "The name of a resource"; | ||
. | ||
|
||
regen:landManagementPractices a rdf:Property ; | ||
rdfs:label "Land Management Practices" ; | ||
rdfs:domain regen:Project ; | ||
rdfs:range schema:ItemList; | ||
rdfs:comment "Land management practices used by the project (ex. no-till, cover cropping, etc...)"; | ||
. | ||
|
||
regen:CertificationProtocol a rdfs:Class ; | ||
rdfs:comment "A certification protocol used for tracking project co-benefits" ; | ||
rdfs:label "Certification Protocol" ; | ||
. | ||
|
||
regen:Methodology rdfs:subClassOf regen:CertificationProtocol; | ||
. | ||
|
||
regen:documentId a rdf:Property ; | ||
rdfs:label "Document ID" ; | ||
rdfs:domain regen:CertificationProtocol ; | ||
rdfs:range xsd:string ; | ||
rdfs:comment "The identifier of the document." . | ||
|
||
schema:url a rdf:Property ; | ||
rdfs:label "URL" ; | ||
rdfs:domain regen:CertificationProtocol; | ||
rdfs:range schema:URL ; | ||
rdfs:comment "The URL of the resource." . | ||
|
||
schema:version a rdf:Property ; | ||
rdfs:label "Version" ; | ||
rdfs:domain regen:CertificationProtocol ; | ||
rdfs:range xsd:string ; | ||
rdfs:comment "The version of the resource." | ||
. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "next/core-web-vitals" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). | ||
|
||
## Getting Started | ||
|
||
First, run the development server: | ||
|
||
```bash | ||
yarn dev | ||
``` | ||
|
||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. | ||
|
||
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. | ||
|
||
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font. | ||
|
||
## Learn More | ||
|
||
To learn more about Next.js, take a look at the following resources: | ||
|
||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. | ||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. | ||
|
||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! | ||
|
||
## Deploy on Vercel | ||
|
||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. | ||
|
||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** @type {import('next').NextConfig} */ | ||
module.exports = { | ||
experimental: { appDir: true }, | ||
webpack(config) { | ||
config.experiments = { ...config.experiments, topLevelAwait: true }; | ||
return config; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "regen-schema-js", | ||
"version": "0.1.0", | ||
"private": true, | ||
"scripts": { | ||
"dev": "next dev", | ||
"build": "next build", | ||
"start": "next start", | ||
"lint": "next lint" | ||
}, | ||
"dependencies": { | ||
"@types/node": "20.1.2", | ||
"@types/react": "18.2.8", | ||
"@types/react-dom": "18.2.4", | ||
"@zeit/next-css": "^1.0.1", | ||
"autoprefixer": "10.4.14", | ||
"encoding": "^0.1.13", | ||
"eslint": "8.40.0", | ||
"eslint-config-next": "13.4.1", | ||
"fs-extra": "^11.1.1", | ||
"next": "13.4.1", | ||
"postcss": "8.4.23", | ||
"postcss-flexbugs-fixes": "^5.0.2", | ||
"postcss-preset-env": "^8.4.1", | ||
"rdflib": "^2.2.32", | ||
"react": "18.2.0", | ||
"react-dom": "18.2.0", | ||
"tailwindcss": "npm:@tailwindcss/postcss7-compat", | ||
"typescript": "5.1.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import fs from "fs/promises"; | ||
import path from "path"; | ||
import * as rdf from "rdflib"; | ||
|
||
import ClassView from "../../components/ClassView"; | ||
import PropertyView from "../../components/PropertyView"; | ||
import { Property, Class } from "../../types"; | ||
|
||
import { BASE_URI, REGEN, RDF, RDFS } from "../../utils/namespaces"; | ||
|
||
export const generateStaticParams = async () => { | ||
const filePath = path.join(process.cwd(), "../rdfs", `regen.ttl`); | ||
const fileContents = await fs.readFile(filePath, "utf8"); | ||
|
||
// Parse the RDF data | ||
const store = rdf.graph(); | ||
rdf.parse(fileContents, store, BASE_URI, "text/turtle"); | ||
|
||
const classStatements = store | ||
.statementsMatching(undefined, RDF("type"), RDFS("Class")) | ||
.filter((statement) => statement.subject.value.startsWith(BASE_URI)); | ||
|
||
const propertyStatements = store | ||
.statementsMatching(undefined, RDF("type"), RDF("Property")) | ||
.filter((statement) => statement.subject.value.startsWith(BASE_URI)); | ||
|
||
const params = classStatements | ||
.concat(propertyStatements) | ||
.map((statement) => ({ | ||
item: statement.subject.value.split("#").pop(), | ||
})); | ||
|
||
return params; | ||
}; | ||
|
||
const getItem = async (itemSlug: string) => { | ||
const filePath = path.join(process.cwd(), "../rdfs", `regen.ttl`); | ||
const fileContents = await fs.readFile(filePath, "utf8"); | ||
|
||
// Parse the RDF data | ||
const store = rdf.graph(); | ||
rdf.parse(fileContents, store, BASE_URI, "text/turtle"); | ||
const item = REGEN(`${itemSlug}`); | ||
|
||
const itemType = store.any(item, RDF("type")); | ||
if (!itemType) throw new Error(`No type found for ${item}`); | ||
|
||
if (itemType.value == RDF("Property").value) { | ||
// Fetch property data | ||
const label = store.any(item, RDFS("label"))?.value; | ||
const comment = store.any(item, RDFS("comment"))?.value; | ||
const ranges = store | ||
.statementsMatching(item, RDFS("range"), undefined) | ||
.map((statement) => statement.object.value); | ||
const domains = store | ||
.statementsMatching(item, RDFS("domain"), undefined) | ||
.map((statement) => statement.object.value); | ||
|
||
return { | ||
type: "property", | ||
iri: item.value, | ||
label, | ||
description: comment, | ||
ranges, | ||
domains, | ||
}; | ||
} else if (itemType.value == RDFS("Class").value) { | ||
// Fetch class data | ||
const label = store.any(item, RDFS("label"))?.value; | ||
const comment = store.any(item, RDFS("comment"))?.value; | ||
const properties = store | ||
.statementsMatching(undefined, RDFS("domain"), item) | ||
.map((statement) => { | ||
const label = statement.subject.value; | ||
const ranges = store | ||
.statementsMatching(statement.subject, RDFS("range"), undefined) | ||
.map((propRange) => { | ||
return propRange.object.value; | ||
}); | ||
const description = store.any( | ||
statement.subject, | ||
RDFS("comment") | ||
)?.value; | ||
return { type: "property", label, ranges, description }; | ||
}); | ||
|
||
return { | ||
type: "class", | ||
iri: item.value, | ||
label, | ||
description: comment, | ||
properties, | ||
}; | ||
} else { | ||
throw new Error(`Unhandled type for ${item}`); | ||
} | ||
}; | ||
|
||
const ItemPage = async ({ params }: { params: { item: string } }) => { | ||
const itemSlug = params.item; | ||
|
||
const item = await getItem(itemSlug); | ||
const componentType = item.type; | ||
const isClass = componentType === "class"; | ||
const isProperty = componentType === "property"; | ||
|
||
return <> | ||
{isClass && <ClassView {...(item as Class)} />} | ||
{isProperty && <PropertyView {...(item as Property)} />} | ||
</> | ||
}; | ||
|
||
export default ItemPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Link from "next/link"; | ||
import "../styles/globals.css"; | ||
|
||
function RootLayout({ children }: { children: React.ReactNode }) { | ||
return ( | ||
<html lang="en"> | ||
<body className="h-screen"> | ||
<header className="p-4 bg-green-500 text-gray-700 font-bold"> | ||
<Link href="/">schema.regen.network</Link> | ||
</header> | ||
{children} | ||
</body> | ||
</html> | ||
); | ||
} | ||
|
||
export default RootLayout; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is mostly a dummy file with some basic data to see what setting up a website that renders based on RDFS ontologies would look like.
After further research, I do think that it might be best for us to lean into OWL ontologies instead, but curious to hear others' feedback on that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you share more on that @clevinson?
BTW reading the articles you've shared is on my TODO list https://archive.topquadrant.com/owl-blog/ vs https://triply.cc/blog/2021-08-why-we-use-owl/