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

<a> tag mapping to manage URL #fragment #1440

Merged
merged 26 commits into from
Sep 25, 2019

Conversation

gfoo
Copy link

@gfoo gfoo commented Sep 17, 2019

resolves #1346

@gfoo
Copy link
Author

gfoo commented Sep 18, 2019

  • Add URL #fragment <a> mapping
  • knora-ontologies/standoff-data.ttl generation (@loicjaouen @tobiasschweizer any docs somewhere?)
  • Update Knora doc
  • Add test
  • Upgrade script

@gfoo
Copy link
Author

gfoo commented Sep 18, 2019

@loicjaouen @tobiasschweizer any docs somewhere?

I think I have to:

  1. create the standard-mapping.json
{
    "knora-api:mappingHasName": "???",
    "knora-api:attachedToProject": {
        "@id": "???"
    },
    "rdfs:label": "???",
    "@context": {
        "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
        "knora-api": "http://api.knora.org/ontology/knora-api/v2#"
    }
}
  1. call the endpoint to generate the new mapping:
$ curl -u [email protected]:test -X POST -F [email protected] -F [email protected]  http://localhost:3333/v2/mapping
  1. generate the ttl:
PREFIX knora-base: <http://www.knora.org/ontology/knora-base#>
Construct {
    ?mapping ?p ?o .
    ?mapping knora-base:hasMappingElement ?mEle .
    ?mEle ?pp ?oo .
    ?oo ?ppp ?ooo .
}
WHERE {
    BIND(<http://rdfh.ch/standoff/mappings/StandardMapping> as ?mapping)
    ?mapping ?p ?o .

    OPTIONAL {
        ?mapping knora-base:hasMappingElement ?mEle .
    	OPTIONAL {
        	?mEle ?pp ?oo .
    		OPTIONAL {
        		?oo ?ppp ?ooo .
            }
        }
    }
}

To update this file knora-ontologies/standoff-data.ttl

@gfoo
Copy link
Author

gfoo commented Sep 18, 2019

I'm a little afraid of updating the ttl using a sparql query because of IRIs... maybe we should update the ttl by hand? :|

And what about the upgrading of an existing Knora base?

@tobiasschweizer
Copy link
Contributor

tobiasschweizer commented Sep 18, 2019

Yes, I think you have to add the new element to /Users/tobi/gitreps/Knora_github/webapi/_test_data/test_route/texts/mappingForStandardHTML.xml, create the new mapping in Knora and update /Users/tobi/gitreps/Knora_github/knora-ontologies/standoff-data.ttl.

Maybe you can do this incrementally, otherwise the IRIs will be all different and every TextValue with standoff would have to be updated (its reference to the mapping).

@tobiasschweizer
Copy link
Contributor

I'm a little afraid of updating the ttl using a sparql query because of IRIs.

I am suffering from PTSD: posttraumatic standoff disorder myself ..

@gfoo
Copy link
Author

gfoo commented Sep 18, 2019

@tobiasschweizer is there any tests to update?

@tobiasschweizer @benjamingeer As you can see in this commit 380121a I have just to add few triplets to an existing Knora base to upgrade it. Is that correct for you? Any guide lines or I just try to copy/paste the way you are doing your upgrade scripts in upgrade folder?

@tobiasschweizer
Copy link
Contributor

is there any tests to update?

You added an element to the existing mapping, so everything is expected to run as before (so the tests should pass).

I think you should add a test that checks the new element.

@gfoo
Copy link
Author

gfoo commented Sep 18, 2019

I think you should add a test that checks the new element.

in which test file? (sorry, never used your test framework...)

@tobiasschweizer
Copy link
Contributor

in which test file?

that would be /Users/tobi/gitreps/Knora_github/webapi/src/test/scala/org/knora/webapi/e2e/v1/StandoffV1R2RSpec.scala

@gfoo
Copy link
Author

gfoo commented Sep 18, 2019

Not very confortable with the CI failed, any clues?

@tobiasschweizer
Copy link
Contributor

@gfoo
Copy link
Author

gfoo commented Sep 18, 2019

@tobiasschweizer
I don't understand why the test perform a fulltext search for 'Dinge' fails, probably a side effect of my modification of standoff-data.ttl, but why?

It seems that an internal-link appears in the result (generating the diff error). If the test data come from the anything-data.ttl, there is no such data like that.

The cited value in the result is a TextValue containing a StandoffLinkTag but not an internal link...

@tobiasschweizer
Copy link
Contributor

I don't understand why the test perform a fulltext search for 'Dinge' fails, probably a side effect of my modification of standoff-data.ttl, but why?

I think this is because the mapping is returned as well at it contains more elements than before.

@gfoo
Copy link
Author

gfoo commented Sep 19, 2019

I added a v1 test there using this data as input, but when I try to send the same data to the v2 API I get an error:

{
  "@type" : "anything:Thing",
  "anything:hasRichtext" : {
    "@type" : "knora-api:TextValue",
    "knora-api:textValueAsXml" : "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<text><p>ref to note <a class=\"internal-link\" href=\"#_note1\" id=\"_ref-note1\">[1]</a></p><p><a class=\"internal-link\" href=\"#_ref-note1\" id=\"_note1\">[1]</a> note 1</p></text>",
    "knora-api:textValueHasMapping" : {
      "@id" : "http://rdfh.ch/standoff/mappings/StandardMapping"
    }
  },
  "knora-api:attachedToProject" : {
    "@id" : "http://rdfh.ch/projects/0001"
  },
  "rdfs:label" : "test thing",
  "@context" : {
    "rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    "knora-api" : "http://api.knora.org/ontology/knora-api/v2#",
    "rdfs" : "http://www.w3.org/2000/01/rdf-schema#",
    "xsd" : "http://www.w3.org/2001/XMLSchema#",
    "anything" : "http://0.0.0.0:3333/ontology/0001/anything/v2#"
  }
}
{
    "knora-api:error": "org.knora.webapi.AssertionException: Resource <http://rdfh.ch/0001/JdZmxDDiSvi_OqU7I5Ur0g> was saved, but one or more of its values are not correct",
    "@context": {
        "knora-api": "http://api.knora.org/ontology/knora-api/v2#"
    }
}

@benjamingeer it sounds like an encoding problem?

@gfoo
Copy link
Author

gfoo commented Sep 19, 2019

I'm going to try this test there

@gfoo
Copy link
Author

gfoo commented Sep 19, 2019

Error is repoduced there: https://travis-ci.org/dhlab-basel/Knora/jobs/586938555#L570

Update: not really reporduced because the errors are differents:

  • First error found using v2 API was saved, but one or more of its values are not correct
  • Error found by the test is not the same as the one that was submitted

@gfoo
Copy link
Author

gfoo commented Sep 20, 2019

@benjamingeer my test above reveals an error described here #1221 (fixed here #1224)

Don't know if it is related to my first error: was saved, but one or more of its values are not correct ?

@tobiasschweizer
Copy link
Contributor

tobiasschweizer commented Sep 25, 2019

@benjamingeer

That would be great, because I don't understand what you mean by standoff attribute conversions.

Please see 41475fd. Does this make sense to you?

@tobiasschweizer
Copy link
Contributor

The SPARQL results for a StandoffInternalReferenceTag should include knora-base:targetHasOriginalXMLID. Try it and see.

I ran a v1 test to create the test data.

@benjamingeer
Copy link

I ran a v1 test to create the test data.

OK but your test is in v2. It would make sense to test both cases.

@tobiasschweizer
Copy link
Contributor

OK but your test is in v2. It would make sense to test both cases.

StandoffUtilV2 is used both in v2 and v1. Yes, I will try to produce tests data for v2 too.

val originalId: String = standoffAssertions(value).getOrElse(OntologyConstants.KnoraBase.StandoffTagHasOriginalXMLID, throw InconsistentTriplestoreDataException(s"referred standoff $value node has no original XML id"))

// If a v2 SPARQL template was used, the XML ID is in this standoff tag.
val originalId: String = standoffTagAssertions.get(OntologyConstants.KnoraBase.TargetHasOriginalXMLID) match {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is used for v2.


case None =>
// If a v1 SPARQL template was used, we have to get the target node and to get its XML ID.
standoffAssertions(value).getOrElse(OntologyConstants.KnoraBase.StandoffTagHasOriginalXMLID, throw InconsistentTriplestoreDataException(s"referred standoff $value node has no original XML id"))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is used for v1.

@tobiasschweizer
Copy link
Contributor

Ok I added tests for v1 and v2 in 40be041

Sorry, but I still don't understand the v2 case: Wouldn't createStandoffTagsV2FromSelectResults only be called after all pages of standoff have been gathered?

@tobiasschweizer
Copy link
Contributor

Or are the pages of standoffAssertions converted to StandoffTagV2 in single steps and combined?

@benjamingeer
Copy link

The method createStandoffTagsV2FromSelectResults is called by createStandoffTagsV2FromConstructResults, which is called by ConstructResponseUtilV2.makeTextValueContentV2 for each page of standoff results. This is how the standoff route returns one page of standoff at a time to the client. I really recommend reading the comments in ConstructResponseUtilV2.makeTextValueContentV2.

@tobiasschweizer
Copy link
Contributor

Ok, I understand! So v2 needs to read standoff in parts.

I really recommend reading the comments in ConstructResponseUtilV2.makeTextValueContentV2.

This the last day I can work on this before my holiday and I really try the best to be helpful.

@benjamingeer
Copy link

I really try the best to be helpful.

And I'm trying to be helpful by writing comments in the code so you can read them. :)

@tobiasschweizer
Copy link
Contributor

And I'm trying to be helpful by writing comments in the code so you can read them. :)

Normally I would have. But today I just wanted to add that additional test ;-) You know how it is ...

@benjamingeer
Copy link

OK I think that should fix it, let's see if all the tests pass.

@tobiasschweizer
Copy link
Contributor

OK I think that should fix it, let's see if all the tests pass.

great, thx.

@benjamingeer
Copy link

@tobiasschweizer Can we merge this now?

Copy link
Contributor

@tobiasschweizer tobiasschweizer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gfoo Thanks for this PR!

That was a quick and easy one ;-)

@tobiasschweizer
Copy link
Contributor

@benjamingeer Yes, please go ahead.

@tobiasschweizer
Copy link
Contributor

or as we say in Swiss German: "möööörtsch"

@benjamingeer benjamingeer merged commit 08b4aa6 into develop Sep 25, 2019
@benjamingeer benjamingeer deleted the wip/standoff-internal-anchor branch September 25, 2019 18:14
@benjamingeer
Copy link

@tobiasschweizer Thanks for your help, and have a good holiday!

@gfoo
Copy link
Author

gfoo commented Sep 25, 2019

what a triplet team... ah ah ah :^)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Richtext/HTML in page anchor link
3 participants