Skip to content
Snippets Groups Projects
Commit 81840846 authored by Arkhangelskiy, Timofey's avatar Arkhangelskiy, Timofey
Browse files

Add templates for searchRetrieve response (not tested yet)

parent 7e5af69b
Branches
No related tags found
No related merge requests found
......@@ -30,6 +30,13 @@ class DiagnosticTypes(str, Enum):
sru = 'sru' # Defined at http://www.loc.gov/standards/sru/diagnostics/diagnosticsList.html
fcs = 'fcs' # Defined in the FCS specifications, 4.2
class DataView(str, Enum):
# Data view (simple hits / multi-layered hits with annotation)
hits = 'hits'
adv = 'adv'
if __name__ == '__main__':
pass
from .enums import *
from .diagnostics import Diagnostic
from .config import ResourceConfig
class Record:
"""
Per FCS specifications, one hit should be encoded as one record,
even though in SRU, records can contain resources, resources
can contain resource fragments, and they, in turn, can contain
multiple hits. Here, each record contains exactly one resource
with exactly one fragment with exactly one hit.
"""
def __init__(self, dataView: DataView):
self.dataView = dataView
# For simple search:
self.text = ''
# For advanced search:
self.segments = []
self.layers = []
def as_dict(self):
"""
Returns a dictionary for insertion into the XML template.
"""
record = {
'resources': {
'resource_fragments': [{
'dv_hits': [{
'text': self.text
}],
'dv_adv': []
}]
}
}
if self.dataView == DataView.adv:
record['resources']['resource_fragments'][0]['dv_adv'].append({
'segments': self.segments,
'layers': self.layers
})
return record
if __name__ == '__main__':
pass
......@@ -2,8 +2,14 @@ p. 3: "The value of the @version attribute MUST be 2." But SRU 1.2 EndpointDescr
p. 4: Link 'section "Layers"' leads to a CLARIN-internal Trac instance.
p. 10: "Send explain request without version and operation parameter" -- but an explain request has to have the operation parameter with 'explain' as its value
p. 8-9: Links to the .xsd's lead to a CLARIN-internal Trac instance.
p. 9-10: In the advanced search results, how does a client understand which layer is which? They don't contain any unique identifiers such as 'pos' or 'word'. They only contain some arbitrary IDs (<Layer id="...">). By the way, I don't understand what those IDs are and where I get them from. Just write something random out of my head?
p. 10: "Send explain request without version and operation parameter" -- but an explain request has to have the operation parameter with 'explain' as its value, as is stated somewhere nearby. UPDATE: SRU documentation says that, indeed, an empty request is treated as an explain request. Maybe this exception is worth mentioning this explicitly here.
p. 14: x-cmd-resource-info parameter present in the query example, but never explained (mentioned in some 2013 slides on FCS; should now probably be x-fcs-endpoint-description)
p. 12 and elsewhere: http://explain.z3950.org/dtd/2.0/ mentioned as the URL of the record schema, but its actual URL is http://zeerex.z3950.org/dtd/zeerex-2.0.dtd .
\ No newline at end of file
p. 12 and elsewhere: http://explain.z3950.org/dtd/2.0/ mentioned as the URL of the record schema, but its actual URL is http://zeerex.z3950.org/dtd/zeerex-2.0.dtd .
p. 14: What is the sruResponse prefix? It is never mentioned. No namespace is provided here, so the example is actually invalid XML. (Who doesn't validate their examples before showing them to a wide audience -- in an official specification, no less??) Maybe sru was actually meant (see p. 2 and an SRU v. 1.2 example above)?
\ No newline at end of file
<fcs:DataView type="application/x-clarin-fcs-adv+xml">
{% for hit in rf.dv_adv %}
<adv:Advanced unit="item">
<adv:Segments>{% for seg in hit.segments %}
<adv:Segment id="{{ seg.id }}" start="{{ seg.start }}" end="{{ seg.end }}"{% if seg.ref %} ref="{{ seg.ref }}"{% endif %}/>
</adv:Segments>{% for layer in hit.layers %}
<Layer id="{{ layer.id }}">{% for span in layer.spans %}
<Span ref="{{ span.ref }}"{% if span.alt_value %} alt-value="{{ span.alt_value }}"{% endif %}{% if span.highlight %} highlight="{{ span.highlight }}"{% endif %}>{{ span.value }}</Span>
{% endfor %}
</Layer>
{% endfor %}
</adv:Advanced>
{% endfor %}
</fcs:DataView>
\ No newline at end of file
File moved
<fcs:DataView type="application/x-clarin-fcs-hits+xml">
{% for hit in rf.dv_hits %}
<hits:Result xmlns:hits="http://clarin.eu/fcs/dataview/hits">
{{ hit.text | safe }}
</hits:Result>
{% endfor %}
</fcs:DataView>
\ No newline at end of file
<fcs:Resource xmlns:fcs="http://clarin.eu/fcs/resource"{% if resource.pid %} pid="{{ resource.pid }}"{% endif %}{% if resource.ref %} resource.ref="{{ resource.ref }}"{% endif %}>{% if resource.dv_cmdi %}{% include 'dataview_cmdi.xml' %}{% endif %}
{% for rf in resource.resource_fragments %}
{% include 'resource_fragment.xml' %}
{% endfor %}
</fcs:Resource>
\ No newline at end of file
<fcs:ResourceFragment {% if rf.pid %} pid="{{ rf.pid }}"{% endif %}{% if rf.ref %} ref="{{ rf.ref }}"{% endif %}>
{% if rf.dv_hits %}{% include 'dataview_hits.xml' %}{% endif %}
{% if rf.dv_adv %}{% include 'dataview_adv.xml' %}{% endif %}
</fcs:ResourceFragment>
\ No newline at end of file
<?xml version='1.0' encoding='utf-8'?>
<sruResponse:searchRetrieveResponse>
<sruResponse:version>2.0</sruResponse:version>
<sruResponse:numberOfRecords>{{ n_hits }}</sruResponse:numberOfRecords>
<sruResponse:records>{% for record in records %}
<sruResponse:record>
<sruResponse:recordSchema>http://clarin.eu/fcs/resource</sruResponse:recordSchema>
<sruResponse:recordXMLEscaping>xml</sruResponse:recordXMLEscaping>
<sruResponse:recordData>{% for resource in record.resources %}
{% include 'resource.xml' %}
{% endfor %}
</sruResponse:recordData>
<sruResponse:recordPosition>{{ loop.index }}</sruResponse:recordPosition>
</sruResponse:record>
{% endfor %}
</sruResponse:records>{% if n_hits > record.resources|length %}
<sruResponse:nextRecordPosition>{{ record.resources|length + 1 }}</sruResponse:nextRecordPosition>{% endif %}
<sruResponse:resultCountPrecision>info:srw/vocabulary/resultCountPrecision/1/exact</sruResponse:resultCountPrecision>
</sruResponse:searchRetrieveResponse>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment