-
Notifications
You must be signed in to change notification settings - Fork 2
Feature/155 rdfa parser #229
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a182de7
init of parser with jsop as html parser
MaillPierre 4d0b1e3
Basic structure based on official presentation
MaillPierre 4964c71
Better processing init
MaillPierre 636eaeb
Parsing up to step 5
MaillPierre 8d7795d
Full algorithm implemented
MaillPierre f0cddec
Fixing IRIUtils for IRI without a localname
MaillPierre fd8cabe
fix step 7
MaillPierre 03a6df6
Minor fixes for litterals, model and IRIs ccomparison
MaillPierre 9859322
Fixing base declaration
MaillPierre 36efed7
fixing corese literal generation
MaillPierre 5bec1c3
fixing inheritance
MaillPierre bf6500f
RDFa parser finalized
MaillPierre 5ad9507
cleaning
MaillPierre da7b123
fix file format
MaillPierre 35e06af
reviews additions
MaillPierre 35fd285
cosmetic
MaillPierre 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
176 changes: 176 additions & 0 deletions
176
src/main/java/fr/inria/corese/core/next/impl/io/parser/rdfa/RDFaEvaluationContext.java
|
MaillPierre marked this conversation as resolved.
|
This file contains hidden or 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,176 @@ | ||
| package fr.inria.corese.core.next.impl.io.parser.rdfa; | ||
|
|
||
| import fr.inria.corese.core.next.api.IRI; | ||
| import fr.inria.corese.core.next.api.Resource; | ||
| import fr.inria.corese.core.next.api.Value; | ||
| import fr.inria.corese.core.next.impl.io.parser.rdfa.model.RDFaIncompleteStatement; | ||
|
|
||
| import java.util.*; | ||
|
|
||
| /** | ||
| * This class is to be used during the evaluation of an HTML file to generate triples during the DOM traversal. | ||
| * @see <a href="https://www.w3.org/TR/rdfa-syntax/#sec_5.2.">RDFa recommandation<a/> | ||
| */ | ||
| public class RDFaEvaluationContext { | ||
|
|
||
| /** | ||
| * This will usually be the URL of the document being processed, but it could be some other URL, set by some other mechanism, such as the XHTML base element. The important thing is that it establishes a URL against which relative paths can be resolved. | ||
| */ | ||
| private IRI baseIri; | ||
|
|
||
| /** | ||
| * The initial value will be the same as the initial value of [base], but it will usually change during the course of processing. | ||
| */ | ||
| private Resource parentSubjectResource ; | ||
|
|
||
| /** | ||
| * In some situations the object of a statement becomes the subject of any nested statements, and this property is used to convey this value. Note that this value may be a bnode, since in some situations a number of nested statements are grouped together on one bnode. This means that the bnode must be set in the containing statement and passed down, and this property is used to convey this value. | ||
| */ | ||
| private Resource parentObjectResource = null; | ||
|
|
||
| /** | ||
| * An index of locally defined IRI prefixes | ||
| */ | ||
| private Map<String, IRI> uriMappings = new HashMap<>(); | ||
|
|
||
| /** | ||
| * Set of statement in the process of building. | ||
| */ | ||
| private Set<RDFaIncompleteStatement> incompleteStatement = new HashSet<>(); | ||
|
|
||
| /** | ||
| * The language of the document. Note that there is no default language. | ||
| */ | ||
| private String language = null; | ||
|
|
||
| public RDFaEvaluationContext(IRI baseIri) { | ||
| this.baseIri = baseIri; | ||
| this.parentSubjectResource = baseIri; | ||
| } | ||
|
|
||
| public RDFaEvaluationContext(IRI baseIri, IRI parentSubjectResource) { | ||
| this.baseIri = baseIri; | ||
| this.parentSubjectResource = parentSubjectResource; | ||
| } | ||
|
|
||
| public RDFaEvaluationContext(RDFaEvaluationContext context) { | ||
| this.baseIri = context.baseIri; | ||
| this.parentSubjectResource = context.parentSubjectResource; | ||
| this.parentObjectResource = context.parentObjectResource; | ||
| this.uriMappings = new HashMap<>(context.uriMappings); | ||
| this.incompleteStatement = new HashSet<>(context.incompleteStatement); | ||
| this.language = context.language; | ||
| } | ||
|
|
||
| public IRI baseIri() { | ||
| return baseIri; | ||
| } | ||
|
|
||
| public RDFaEvaluationContext baseIri(IRI baseIri) { | ||
| this.baseIri = baseIri; | ||
| return this; | ||
| } | ||
|
|
||
| public RDFaEvaluationContext incompleteStatements(Set<RDFaIncompleteStatement> incompleteStatement) { | ||
| this.incompleteStatement = new HashSet<>(incompleteStatement); | ||
| return this; | ||
| } | ||
|
|
||
| public Iterator<RDFaIncompleteStatement> getIncompleteStatementIterator() { | ||
| return this.incompleteStatement.iterator(); | ||
| } | ||
|
|
||
| public RDFaEvaluationContext addStatementWithoutSubject(IRI property, Value object) { | ||
| RDFaIncompleteStatement newStatement = new RDFaIncompleteStatement(property); | ||
| newStatement.setObject(object); | ||
| this.incompleteStatement.add(newStatement); | ||
| return this; | ||
| } | ||
|
|
||
| public RDFaEvaluationContext addStatementWithoutObject(Resource subject, IRI property) { | ||
| RDFaIncompleteStatement newStatement = new RDFaIncompleteStatement(property); | ||
| newStatement.setSubject(subject); | ||
| this.incompleteStatement.add(newStatement); | ||
| return this; | ||
| } | ||
|
|
||
| public void clearIncompleteStatements() { | ||
| this.incompleteStatement.clear(); | ||
| } | ||
|
|
||
| public Resource parentSubjectResource() { | ||
| return parentSubjectResource; | ||
| } | ||
|
|
||
| public RDFaEvaluationContext parentSubjectResource(Resource parentSubjectResource) { | ||
| this.parentSubjectResource = parentSubjectResource; | ||
| return this; | ||
| } | ||
|
|
||
| public Resource parentObjectResource() { | ||
| return parentObjectResource; | ||
| } | ||
|
|
||
| public RDFaEvaluationContext parentObjectResource(Resource parentObjectResource) { | ||
| this.parentObjectResource = parentObjectResource; | ||
| return this; | ||
| } | ||
|
|
||
| public Map<String, IRI> uriMappings() { | ||
| return uriMappings; | ||
| } | ||
|
|
||
| public RDFaEvaluationContext uriMappings(Map<String, IRI> uriMappings) { | ||
| this.uriMappings = uriMappings; | ||
| return this; | ||
| } | ||
|
|
||
| public boolean hasUriMapping(String prefix) { | ||
| return this.uriMappings.containsKey(prefix); | ||
| } | ||
|
|
||
| /** | ||
| * @param prefix the prefix WITHOUT ":" | ||
| * @return the IRI associated to the prefix in this context | ||
| */ | ||
| public IRI uriMapping(String prefix) { | ||
| return this.uriMappings.get(prefix); | ||
| } | ||
|
|
||
| public void addUriMapping(String prefix, IRI prefixIri) { | ||
| this.uriMappings.put(prefix, prefixIri); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| StringBuilder sb = new StringBuilder(); | ||
|
|
||
| sb.append("BaseURI: ").append(this.baseIri.stringValue()).append(" "); | ||
| sb.append("Mappings: ["); | ||
| this.uriMappings.forEach((key, value) -> sb.append("(").append(key).append(", ").append(value.stringValue()).append(") ")); | ||
| sb.append("] "); | ||
| if(this.parentSubjectResource != null) { | ||
| sb.append("Subject:").append(this.parentSubjectResource.stringValue()).append(" "); | ||
| } else { | ||
| sb.append("Subject:").append((Object) null).append(" "); | ||
| } | ||
| if(this.parentObjectResource != null) { | ||
| sb.append("Object: ").append(this.parentObjectResource.stringValue()).append(" "); | ||
| } else { | ||
| sb.append("Object: ").append((Object) null).append(" "); | ||
| } | ||
| if(! this.incompleteStatement.isEmpty()) { | ||
| sb.append(this.incompleteStatement.size()).append(" incomplete statements."); | ||
| } | ||
|
|
||
| return sb.toString(); | ||
| } | ||
|
|
||
| public String getLanguage() { | ||
| return language; | ||
| } | ||
|
|
||
| public void setLanguage(String language) { | ||
| this.language = language; | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.