lightly-studio 0.3.2__py3-none-any.whl → 0.3.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of lightly-studio might be problematic. Click here for more details.
- lightly_studio/__init__.py +1 -1
- lightly_studio/api/app.py +6 -4
- lightly_studio/api/db_tables.py +0 -3
- lightly_studio/api/routes/api/annotation.py +26 -0
- lightly_studio/api/routes/api/annotations/__init__.py +7 -0
- lightly_studio/api/routes/api/annotations/create_annotation.py +52 -0
- lightly_studio/api/routes/api/dataset.py +3 -5
- lightly_studio/api/routes/api/embeddings2d.py +104 -0
- lightly_studio/api/routes/api/export.py +73 -0
- lightly_studio/api/routes/api/selection.py +87 -0
- lightly_studio/core/add_samples.py +0 -9
- lightly_studio/core/dataset.py +32 -48
- lightly_studio/core/dataset_query/dataset_query.py +5 -0
- lightly_studio/dataset/env.py +4 -0
- lightly_studio/dataset/file_utils.py +13 -2
- lightly_studio/dataset/loader.py +0 -54
- lightly_studio/dataset/mobileclip_embedding_generator.py +3 -2
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/assets/0.CA_CXIBb.css +1 -0
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/assets/_layout.DS78jgNY.css +1 -0
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/assets/{SelectableSvgGroup.BNTuXSAe.css → index.BVs_sZj9.css} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/assets/{SelectableSvgGroup.BBm0IWdq.css → transform.D487hwJk.css} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/6t3IJ0vQ.js +1 -0
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/{gLNdjSzu.js → 8NsknIT2.js} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/{Cur71c3O.js → BND_-4Kp.js} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/{DRZO-E-T.js → BdfTHw61.js} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/{BqBqV92V.js → BfHVnyNT.js} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/BjkP1AHA.js +1 -0
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/BuuNVL9G.js +1 -0
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/{7YNGEs1C.js → BzKGpnl4.js} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/{C0JiMuYn.js → CCx7Ho51.js} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/{DcGCxgpH.js → CH6P3X75.js} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/CR2upx_Q.js +4 -0
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/CWPZrTTJ.js +1 -0
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/{Ccq4ZD0B.js → Cs1XmhiF.js} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/{OH7-C_mc.js → CwPowJfP.js} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/CxFKfZ9T.js +1 -0
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/Cxevwdid.js +1 -0
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/{C98Hk3r5.js → D4whDBUi.js} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/D6r9vr07.js +1 -0
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/{DqUGznj_.js → DA6bFLPR.js} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/{2O287xak.js → DEgUu98i.js} +2 -2
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/{KpAtIldw.js → DGTPl6Gk.js} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/{Cs31G8Qn.js → DKGxBSlK.js} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/{D8GZDMNN.js → DQXoLcsF.js} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/DQe_kdRt.js +92 -0
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/DcY4jgG3.js +1 -0
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/{Crk-jcvV.js → RmD8FzRo.js} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/V-MnMC1X.js +1 -0
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/{Df3aMO5B.js → keKYsoph.js} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/entry/{app.BI-EA5gL.js → app.BVr6DYqP.js} +2 -2
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/entry/start.u7zsVvqp.js +1 -0
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/nodes/0.Da2agmdd.js +1 -0
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/nodes/{1._I9GR805.js → 1.B11tVRJV.js} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/nodes/{10.J2RBFrSr.js → 10.l30Zud4h.js} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/nodes/{12.Cmqj25a-.js → 12.CgKPGcAP.js} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/nodes/2.C8HLK8mj.js +857 -0
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/nodes/{3.w9g4AcAx.js → 3.CLvg3QcJ.js} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/nodes/{4.BBI8KwnD.js → 4.BQhDtXUI.js} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/nodes/5.-6XqWX5G.js +1 -0
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/nodes/{6.CrbkRPam.js → 6.uBV1Lhat.js} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/nodes/{7.FomEdhD6.js → 7.BXsgoQZh.js} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/nodes/8.BkbcnUs8.js +1 -0
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/nodes/{9.CajIG5ce.js → 9.Bkrv-Vww.js} +1 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/workers/clustering.worker-DKqeLtG0.js +2 -0
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/workers/search.worker-vNSty3B0.js +1 -0
- lightly_studio/dist_lightly_studio_view_app/_app/version.json +1 -1
- lightly_studio/dist_lightly_studio_view_app/index.html +14 -14
- lightly_studio/export/export_dataset.py +65 -0
- lightly_studio/export/lightly_studio_label_input.py +120 -0
- lightly_studio/few_shot_classifier/classifier_manager.py +5 -26
- lightly_studio/metadata/compute_typicality.py +67 -0
- lightly_studio/models/annotation/annotation_base.py +11 -12
- lightly_studio/resolvers/annotation_label_resolver/__init__.py +2 -1
- lightly_studio/resolvers/annotation_label_resolver/get_all.py +15 -0
- lightly_studio/resolvers/annotation_resolver/__init__.py +2 -3
- lightly_studio/resolvers/annotation_resolver/create_many.py +3 -3
- lightly_studio/resolvers/annotation_resolver/delete_annotation.py +1 -1
- lightly_studio/resolvers/annotation_resolver/delete_annotations.py +7 -3
- lightly_studio/resolvers/annotation_resolver/get_by_id.py +19 -1
- lightly_studio/resolvers/annotation_resolver/update_annotation_label.py +0 -1
- lightly_studio/resolvers/annotations/annotations_filter.py +1 -11
- lightly_studio/selection/mundig.py +7 -10
- lightly_studio/selection/selection_config.py +4 -1
- lightly_studio/services/annotations_service/__init__.py +8 -0
- lightly_studio/services/annotations_service/create_annotation.py +63 -0
- lightly_studio/services/annotations_service/delete_annotation.py +22 -0
- {lightly_studio-0.3.2.dist-info → lightly_studio-0.3.3.dist-info}/METADATA +152 -27
- {lightly_studio-0.3.2.dist-info → lightly_studio-0.3.3.dist-info}/RECORD +89 -85
- lightly_studio/api/routes/api/annotation_task.py +0 -37
- lightly_studio/api/routes/api/metrics.py +0 -76
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/assets/0.DenzbfeK.css +0 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/assets/_layout.T-zjSUd3.css +0 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/BBoGk9hq.js +0 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/BRnH9v23.js +0 -92
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/Bg1Y5eUZ.js +0 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/CG0dMCJi.js +0 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/Cpy-nab_.js +0 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/CsKrY2zA.js +0 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/CzgC3GFB.js +0 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/DFRh-Spp.js +0 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/DkR_EZ_B.js +0 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/M1Q1F7bw.js +0 -4
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/chunks/i0ZZ4z06.js +0 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/entry/start.CcsRl3cZ.js +0 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/nodes/0.BbO4Zc3r.js +0 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/nodes/2.C45iKJHA.js +0 -6
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/nodes/5.huHuxdiF.js +0 -1
- lightly_studio/dist_lightly_studio_view_app/_app/immutable/nodes/8.Cb_ADSLk.js +0 -1
- lightly_studio/metrics/__init__.py +0 -0
- lightly_studio/metrics/detection/__init__.py +0 -0
- lightly_studio/metrics/detection/map.py +0 -268
- lightly_studio/models/annotation_task.py +0 -28
- lightly_studio/resolvers/annotation_resolver/create.py +0 -19
- lightly_studio/resolvers/annotation_task_resolver.py +0 -31
- {lightly_studio-0.3.2.dist-info → lightly_studio-0.3.3.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){"use strict";function ce(Q){if(Q.__esModule)return Q;var y=Q.default;if(typeof y=="function"){var z=function E(){return this instanceof E?Reflect.construct(y,arguments,this.constructor):y.apply(this,arguments)};z.prototype=y.prototype}else z={};return Object.defineProperty(z,"__esModule",{value:!0}),Object.keys(Q).forEach(function(E){var q=Object.getOwnPropertyDescriptor(Q,E);Object.defineProperty(z,E,q.get?q:{enumerable:!0,get:function(){return Q[E]}})}),z}var ue={},ae=Object.freeze({__proto__:null,default:ue}),ge=ce(ae);(function(Q){var y;function z(t,i,e){const s=typeof e,n=typeof t;if(s!=="undefined"){if(n!=="undefined"){if(e){if(n==="function"&&s===n)return function(o){return t(e(o))};if(i=t.constructor,i===e.constructor){if(i===Array)return e.concat(t);if(i===Map){var r=new Map(e);for(var h of t)r.set(h[0],h[1]);return r}if(i===Set){h=new Set(e);for(r of t.values())h.add(r);return h}}}return t}return e}return n==="undefined"?i:t}function E(t,i){return typeof t>"u"?i:t}function q(){return Object.create(null)}function F(t){return typeof t=="string"}function rt(t){return typeof t=="object"}function ht(t,i){if(F(i))t=t[i];else for(let e=0;t&&e<i.length;e++)t=t[i[e]];return t}const pe=/[^\p{L}\p{N}]+/u,de=/(\d{3})/g,me=/(\D)(\d{3})/g,we=/(\d{3})(\D)/g,Ft=/[\u0300-\u036f]/g;function lt(t={}){if(!this||this.constructor!==lt)return new lt(...arguments);if(arguments.length)for(t=0;t<arguments.length;t++)this.assign(arguments[t]);else this.assign(t)}y=lt.prototype,y.assign=function(t){this.normalize=z(t.normalize,!0,this.normalize);let i=t.include,e=i||t.exclude||t.split,s;if(e||e===""){if(typeof e=="object"&&e.constructor!==RegExp){let n="";s=!i,i||(n+="\\p{Z}"),e.letter&&(n+="\\p{L}"),e.number&&(n+="\\p{N}",s=!!i),e.symbol&&(n+="\\p{S}"),e.punctuation&&(n+="\\p{P}"),e.control&&(n+="\\p{C}"),(e=e.char)&&(n+=typeof e=="object"?e.join(""):e);try{this.split=new RegExp("["+(i?"^":"")+n+"]+","u")}catch{this.split=/\s+/}}else this.split=e,s=e===!1||"a1a".split(e).length<2;this.numeric=z(t.numeric,s)}else{try{this.split=z(this.split,pe)}catch{this.split=/\s+/}this.numeric=z(t.numeric,z(this.numeric,!0))}if(this.prepare=z(t.prepare,null,this.prepare),this.finalize=z(t.finalize,null,this.finalize),e=t.filter,this.filter=typeof e=="function"?e:z(e&&new Set(e),null,this.filter),this.dedupe=z(t.dedupe,!0,this.dedupe),this.matcher=z((e=t.matcher)&&new Map(e),null,this.matcher),this.mapper=z((e=t.mapper)&&new Map(e),null,this.mapper),this.stemmer=z((e=t.stemmer)&&new Map(e),null,this.stemmer),this.replacer=z(t.replacer,null,this.replacer),this.minlength=z(t.minlength,1,this.minlength),this.maxlength=z(t.maxlength,1024,this.maxlength),this.rtl=z(t.rtl,!1,this.rtl),(this.cache=e=z(t.cache,!0,this.cache))&&(this.F=null,this.L=typeof e=="number"?e:2e5,this.B=new Map,this.D=new Map,this.I=this.H=128),this.h="",this.J=null,this.A="",this.K=null,this.matcher)for(const n of this.matcher.keys())this.h+=(this.h?"|":"")+n;if(this.stemmer)for(const n of this.stemmer.keys())this.A+=(this.A?"|":"")+n;return this},y.addStemmer=function(t,i){return this.stemmer||(this.stemmer=new Map),this.stemmer.set(t,i),this.A+=(this.A?"|":"")+t,this.K=null,this.cache&&V(this),this},y.addFilter=function(t){return typeof t=="function"?this.filter=t:(this.filter||(this.filter=new Set),this.filter.add(t)),this.cache&&V(this),this},y.addMapper=function(t,i){return typeof t=="object"?this.addReplacer(t,i):t.length>1?this.addMatcher(t,i):(this.mapper||(this.mapper=new Map),this.mapper.set(t,i),this.cache&&V(this),this)},y.addMatcher=function(t,i){return typeof t=="object"?this.addReplacer(t,i):t.length<2&&(this.dedupe||this.mapper)?this.addMapper(t,i):(this.matcher||(this.matcher=new Map),this.matcher.set(t,i),this.h+=(this.h?"|":"")+t,this.J=null,this.cache&&V(this),this)},y.addReplacer=function(t,i){return typeof t=="string"?this.addMatcher(t,i):(this.replacer||(this.replacer=[]),this.replacer.push(t,i),this.cache&&V(this),this)},y.encode=function(t,i){if(this.cache&&t.length<=this.H)if(this.F){if(this.B.has(t))return this.B.get(t)}else this.F=setTimeout(V,50,this);this.normalize&&(typeof this.normalize=="function"?t=this.normalize(t):t=Ft?t.normalize("NFKD").replace(Ft,"").toLowerCase():t.toLowerCase()),this.prepare&&(t=this.prepare(t)),this.numeric&&t.length>3&&(t=t.replace(me,"$1 $2").replace(we,"$1 $2").replace(de,"$1 "));const e=!(this.dedupe||this.mapper||this.filter||this.matcher||this.stemmer||this.replacer);let s=[],n=q(),r,h,o=this.split||this.split===""?t.split(this.split):[t];for(let f=0,c,a;f<o.length;f++)if((c=a=o[f])&&!(c.length<this.minlength||c.length>this.maxlength)){if(i){if(n[c])continue;n[c]=1}else{if(r===c)continue;r=c}if(e)s.push(c);else if(!this.filter||(typeof this.filter=="function"?this.filter(c):!this.filter.has(c))){if(this.cache&&c.length<=this.I)if(this.F){var l=this.D.get(c);if(l||l===""){l&&s.push(l);continue}}else this.F=setTimeout(V,50,this);if(this.stemmer){this.K||(this.K=new RegExp("(?!^)("+this.A+")$"));let m;for(;m!==c&&c.length>2;)m=c,c=c.replace(this.K,p=>this.stemmer.get(p))}if(c&&(this.mapper||this.dedupe&&c.length>1)){l="";for(let m=0,p="",d,u;m<c.length;m++)d=c.charAt(m),d===p&&this.dedupe||((u=this.mapper&&this.mapper.get(d))||u===""?u===p&&this.dedupe||!(p=u)||(l+=u):l+=p=d);c=l}if(this.matcher&&c.length>1&&(this.J||(this.J=new RegExp("("+this.h+")","g")),c=c.replace(this.J,m=>this.matcher.get(m))),c&&this.replacer)for(l=0;c&&l<this.replacer.length;l+=2)c=c.replace(this.replacer[l],this.replacer[l+1]);if(this.cache&&a.length<=this.I&&(this.D.set(a,c),this.D.size>this.L&&(this.D.clear(),this.I=this.I/1.1|0)),c){if(c!==a)if(i){if(n[c])continue;n[c]=1}else{if(h===c)continue;h=c}s.push(c)}}}return this.finalize&&(s=this.finalize(s)||s),this.cache&&t.length<=this.H&&(this.B.set(t,s),this.B.size>this.L&&(this.B.clear(),this.H=this.H/1.1|0)),s};function V(t){t.F=null,t.B.clear(),t.D.clear()}function _t(t,i,e){e||(i||typeof t!="object"?typeof i=="object"&&(e=i,i=0):e=t),e&&(t=e.query||t,i=e.limit||i);let s=""+(i||0);e&&(s+=(e.offset||0)+!!e.context+!!e.suggest+(e.resolve!==!1)+(e.resolution||this.resolution)+(e.boost||0)),t=(""+t).toLowerCase(),this.cache||(this.cache=new X);let n=this.cache.get(t+s);if(!n){const r=e&&e.cache;r&&(e.cache=!1),n=this.search(t,i,e),r&&(e.cache=r),this.cache.set(t+s,n)}return n}function X(t){this.limit=t&&t!==!0?t:1e3,this.cache=new Map,this.h=""}X.prototype.set=function(t,i){this.cache.set(this.h=t,i),this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)},X.prototype.get=function(t){const i=this.cache.get(t);return i&&this.h!==t&&(this.cache.delete(t),this.cache.set(this.h=t,i)),i},X.prototype.remove=function(t){for(const i of this.cache){const e=i[0];i[1].includes(t)&&this.cache.delete(e)}},X.prototype.clear=function(){this.cache.clear(),this.h=""};const Tt={normalize:!1,numeric:!1,dedupe:!1},at={},jt=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]),Kt=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Gt=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"],Jt={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,ß:2,d:3,t:3,l:4,m:5,n:5,r:6};var Wt={Exact:Tt,Default:at,Normalize:at,LatinBalance:{mapper:jt},LatinAdvanced:{mapper:jt,matcher:Kt,replacer:Gt},LatinExtra:{mapper:jt,replacer:Gt.concat([/(?!^)[aeo]/g,""]),matcher:Kt},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(t){for(let e=0;e<t.length;e++){var i=t[e];let s=i.charAt(0),n=Jt[s];for(let r=1,h;r<i.length&&(h=i.charAt(r),h==="h"||h==="w"||!(h=Jt[h])||h===n||(s+=h,n=h,s.length!==4));r++);t[e]=s}}},CJK:{split:""},LatinExact:Tt,LatinDefault:at,LatinSimple:at};function Ut(t,i,e,s){let n=[];for(let r=0,h;r<t.index.length;r++)if(h=t.index[r],i>=h.length)i-=h.length;else{i=h[s?"splice":"slice"](i,e);const o=i.length;if(o&&(n=n.length?n.concat(i):i,e-=o,s&&(t.length-=o),!e))break;i=0}return n}function H(t){if(!this||this.constructor!==H)return new H(t);this.index=t?[t]:[],this.length=t?t.length:0;const i=this;return new Proxy([],{get(e,s){if(s==="length")return i.length;if(s==="push")return function(n){i.index[i.index.length-1].push(n),i.length++};if(s==="pop")return function(){if(i.length)return i.length--,i.index[i.index.length-1].pop()};if(s==="indexOf")return function(n){let r=0;for(let h=0,o,l;h<i.index.length;h++){if(o=i.index[h],l=o.indexOf(n),l>=0)return r+l;r+=o.length}return-1};if(s==="includes")return function(n){for(let r=0;r<i.index.length;r++)if(i.index[r].includes(n))return!0;return!1};if(s==="slice")return function(n,r){return Ut(i,n||0,r||i.length,!1)};if(s==="splice")return function(n,r){return Ut(i,n||0,r||i.length,!0)};if(s==="constructor")return Array;if(typeof s!="symbol")return(e=i.index[s/2**31|0])&&e[s]},set(e,s,n){return e=s/2**31|0,(i.index[e]||(i.index[e]=[]))[s]=n,i.length++,!0}})}H.prototype.clear=function(){this.index.length=0},H.prototype.push=function(){};function T(t=8){if(!this||this.constructor!==T)return new T(t);this.index=q(),this.h=[],this.size=0,t>32?(this.B=Zt,this.A=BigInt(t)):(this.B=Rt,this.A=t)}T.prototype.get=function(t){const i=this.index[this.B(t)];return i&&i.get(t)},T.prototype.set=function(t,i){var e=this.B(t);let s=this.index[e];s?(e=s.size,s.set(t,i),(e-=s.size)&&this.size++):(this.index[e]=s=new Map([[t,i]]),this.h.push(s),this.size++)};function K(t=8){if(!this||this.constructor!==K)return new K(t);this.index=q(),this.h=[],this.size=0,t>32?(this.B=Zt,this.A=BigInt(t)):(this.B=Rt,this.A=t)}K.prototype.add=function(t){var i=this.B(t);let e=this.index[i];e?(i=e.size,e.add(t),(i-=e.size)&&this.size++):(this.index[i]=e=new Set([t]),this.h.push(e),this.size++)},y=T.prototype,y.has=K.prototype.has=function(t){const i=this.index[this.B(t)];return i&&i.has(t)},y.delete=K.prototype.delete=function(t){const i=this.index[this.B(t)];i&&i.delete(t)&&this.size--},y.clear=K.prototype.clear=function(){this.index=q(),this.h=[],this.size=0},y.values=K.prototype.values=function*(){for(let t=0;t<this.h.length;t++)for(let i of this.h[t].values())yield i},y.keys=K.prototype.keys=function*(){for(let t=0;t<this.h.length;t++)for(let i of this.h[t].keys())yield i},y.entries=K.prototype.entries=function*(){for(let t=0;t<this.h.length;t++)for(let i of this.h[t].entries())yield i};function Rt(t){let i=2**this.A-1;if(typeof t=="number")return t&i;let e=0,s=this.A+1;for(let n=0;n<t.length;n++)e=(e*s^t.charCodeAt(n))&i;return this.A===32?e+2**31:e}function Zt(t){let i=BigInt(2)**this.A-BigInt(1);var e=typeof t;if(e==="bigint")return t&i;if(e==="number")return BigInt(t)&i;e=BigInt(0);let s=this.A+BigInt(1);for(let n=0;n<t.length;n++)e=(e*s^BigInt(t.charCodeAt(n)))&i;return e}let tt,ot;async function ye(t){t=t.data;var i=t.task;const e=t.id;let s=t.args;switch(i){case"init":ot=t.options||{},(i=t.factory)?(Function("return "+i)()(self),tt=new self.FlexSearch.Index(ot),delete self.FlexSearch):tt=new G(ot),postMessage({id:e});break;default:let n;i==="export"&&(s[1]?(s[0]=ot.export,s[2]=0,s[3]=1):s=null),i==="import"?s[0]&&(t=await ot.import.call(tt,s[0]),tt.import(s[0],t)):((n=s&&tt[i].apply(tt,s))&&n.then&&(n=await n),n&&n.await&&(n=await n.await),i==="search"&&n.result&&(n=n.result)),postMessage(i==="search"?{id:e,msg:n}:{id:e})}}function Bt(t){et.call(t,"add"),et.call(t,"append"),et.call(t,"search"),et.call(t,"update"),et.call(t,"remove"),et.call(t,"searchCache")}let St,Qt,gt;function be(){St=gt=0}function et(t){this[t+"Async"]=function(){const i=arguments;var e=i[i.length-1];let s;if(typeof e=="function"&&(s=e,delete i[i.length-1]),St?gt||(gt=Date.now()-Qt>=this.priority*this.priority*3):(St=setTimeout(be,0),Qt=Date.now()),gt){const r=this;return new Promise(h=>{setTimeout(function(){h(r[t+"Async"].apply(r,i))},0)})}const n=this[t].apply(this,i);return e=n.then?n:new Promise(r=>r(n)),s&&e.then(s),e}}let U=0;function it(t={},i){function e(o){function l(f){f=f.data||f;const c=f.id,a=c&&r.h[c];a&&(a(f.msg),delete r.h[c])}if(this.worker=o,this.h=q(),this.worker)return n?this.worker.on("message",l):this.worker.onmessage=l,t.config?new Promise(function(f){U>1e9&&(U=0),r.h[++U]=function(){f(r)},r.worker.postMessage({id:U,task:"init",factory:s,options:t})}):(this.priority=t.priority||4,this.encoder=i||null,this.worker.postMessage({task:"init",factory:s,options:t}),this)}if(!this||this.constructor!==it)return new it(t);let s=typeof self<"u"?self._factory:typeof window<"u"?window._factory:null;s&&(s=s.toString());const n=typeof window>"u",r=this,h=xe(s,n,t.worker);return h.then?h.then(function(o){return e.call(r,o)}):e.call(this,h)}R("add"),R("append"),R("search"),R("update"),R("remove"),R("clear"),R("export"),R("import"),it.prototype.searchCache=_t,Bt(it.prototype);function R(t){it.prototype[t]=function(){const i=this,e=[].slice.call(arguments);var s=e[e.length-1];let n;return typeof s=="function"&&(n=s,e.pop()),s=new Promise(function(r){t==="export"&&typeof e[0]=="function"&&(e[0]=null),U>1e9&&(U=0),i.h[++U]=r,i.worker.postMessage({task:t,id:U,args:e})}),n?(s.then(n),this):s}}function xe(t,i,e){return i?new ge.Worker(__dirname+"/worker/node.js"):t?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+ye.toString()],{type:"text/javascript"}))):new window.Worker(typeof e=="string"?e:self.location.href.replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js","module/worker/worker.js").replace("flexsearch.bundle.module.min.mjs","module/worker/worker.js"),{type:"module"})}st.prototype.add=function(t,i,e){if(rt(t)&&(i=t,t=ht(i,this.key)),i&&(t||t===0)){if(!e&&this.reg.has(t))return this.update(t,i);for(let o=0,l;o<this.field.length;o++){l=this.B[o];var s=this.index.get(this.field[o]);if(typeof l=="function"){var n=l(i);n&&s.add(t,n,e,!0)}else n=l.G,(!n||n(i))&&(l.constructor===String?l=[""+l]:F(l)&&(l=[l]),Pt(i,l,this.D,0,s,t,l[0],e))}if(this.tag)for(s=0;s<this.A.length;s++){var r=this.A[s];n=this.tag.get(this.F[s]);let o=q();if(typeof r=="function"){if(r=r(i),!r)continue}else{var h=r.G;if(h&&!h(i))continue;r.constructor===String&&(r=""+r),r=ht(i,r)}if(n&&r){F(r)&&(r=[r]);for(let l=0,f,c;l<r.length;l++)if(f=r[l],!o[f]&&(o[f]=1,(h=n.get(f))?c=h:n.set(f,c=[]),!e||!c.includes(t))){if(c.length===2**31-1){if(h=new H(c),this.fastupdate)for(let a of this.reg.values())a.includes(c)&&(a[a.indexOf(c)]=h);n.set(f,c=h)}c.push(t),this.fastupdate&&((h=this.reg.get(t))?h.push(c):this.reg.set(t,[c]))}}}if(this.store&&(!e||!this.store.has(t))){let o;if(this.h){o=q();for(let l=0,f;l<this.h.length;l++){if(f=this.h[l],(e=f.G)&&!e(i))continue;let c;if(typeof f=="function"){if(c=f(i),!c)continue;f=[f.O]}else if(F(f)||f.constructor===String){o[f]=i[f];continue}Ct(i,o,f,0,f[0],c)}}this.store.set(t,o||i)}this.worker&&(this.fastupdate||this.reg.add(t))}return this};function Ct(t,i,e,s,n,r){if(t=t[n],s===e.length-1)i[n]=r||t;else if(t)if(t.constructor===Array)for(i=i[n]=Array(t.length),n=0;n<t.length;n++)Ct(t,i,e,s,n);else i=i[n]||(i[n]=q()),n=e[++s],Ct(t,i,e,s,n)}function Pt(t,i,e,s,n,r,h,o){if(t=t[h])if(s===i.length-1){if(t.constructor===Array){if(e[s]){for(i=0;i<t.length;i++)n.add(r,t[i],!0,!0);return}t=t.join(" ")}n.add(r,t,o,!0)}else if(t.constructor===Array)for(h=0;h<t.length;h++)Pt(t,i,e,s,n,r,h,o);else h=i[++s],Pt(t,i,e,s,n,r,h,o)}function qt(t,i,e,s){if(!t.length)return t;if(t.length===1)return t=t[0],t=e||t.length>i?t.slice(e,e+i):t,s?nt.call(this,t):t;let n=[];for(let r=0,h,o;r<t.length;r++)if((h=t[r])&&(o=h.length)){if(e){if(e>=o){e-=o;continue}h=h.slice(e,e+i),o=h.length,e=0}if(o>i&&(h=h.slice(0,i),o=i),!n.length&&o>=i)return s?nt.call(this,h):h;if(n.push(h),i-=o,!i)break}return n=n.length>1?[].concat.apply([],n):n[0],s?nt.call(this,n):n}function pt(t,i,e,s){var n=s[0];if(n[0]&&n[0].query)return t[i].apply(t,n);if(!(i!=="and"&&i!=="not"||t.result.length||t.await||n.suggest))return s.length>1&&(n=s[s.length-1]),(s=n.resolve)?t.await||t.result:t;let r=[],h=0,o=0,l,f,c,a,m;for(i=0;i<s.length;i++)if(n=s[i]){var p=void 0;if(n.constructor===P)p=n.await||n.result;else if(n.then||n.constructor===Array)p=n;else{h=n.limit||0,o=n.offset||0,c=n.suggest,f=n.resolve,l=((a=n.highlight||t.highlight)||n.enrich)&&f,p=n.queue;let d=n.async||p,u=n.index,g=n.query;if(u?t.index||(t.index=u):u=t.index,g||n.tag){const b=n.field||n.pluck;if(b&&(!g||t.query&&!a||(t.query=g,t.field=b,t.highlight=a),u=u.index.get(b)),p&&(m||t.await)){m=1;let w;const k=t.C.length,B=new Promise(function(S){w=S});(function(S,j){B.h=function(){j.index=null,j.resolve=!1;let A=d?S.searchAsync(j):S.search(j);return A.then?A.then(function(x){return t.C[k]=x=x.result||x,w(x),x}):(A=A.result||A,w(A),A)}})(u,Object.assign({},n)),t.C.push(B),r[i]=B;continue}else n.resolve=!1,n.index=null,p=d?u.searchAsync(n):u.search(n),n.resolve=f,n.index=u}else if(n.and)p=dt(n,"and",u);else if(n.or)p=dt(n,"or",u);else if(n.not)p=dt(n,"not",u);else if(n.xor)p=dt(n,"xor",u);else continue}p.await?(m=1,p=p.await):p.then?(m=1,p=p.then(function(d){return d.result||d})):p=p.result||p,r[i]=p}if(m&&!t.await&&(t.await=new Promise(function(d){t.return=d})),m){const d=Promise.all(r).then(function(u){for(let g=0;g<t.C.length;g++)if(t.C[g]===d){t.C[g]=function(){return e.call(t,u,h,o,l,f,c,a)};break}zt(t)});t.C.push(d)}else if(t.await)t.C.push(function(){return e.call(t,r,h,o,l,f,c,a)});else return e.call(t,r,h,o,l,f,c,a);return f?t.await||t.result:t}function dt(t,i,e){t=t[i];const s=t[0]||t;return s.index||(s.index=e),e=new P(s),t.length>1&&(e=e[i].apply(e,t.slice(1))),e}P.prototype.or=function(){return pt(this,"or",ve,arguments)};function ve(t,i,e,s,n,r,h){return t.length&&(this.result.length&&t.push(this.result),t.length<2?this.result=t[0]:(this.result=Vt(t,i,e,!1,this.h),e=0)),n&&(this.await=null),n?this.resolve(i,e,s,h):this}P.prototype.and=function(){return pt(this,"and",ke,arguments)};function ke(t,i,e,s,n,r,h){if(!r&&!this.result.length)return n?this.result:this;let o;if(t.length)if(this.result.length&&t.unshift(this.result),t.length<2)this.result=t[0];else{let l=0;for(let f=0,c,a;f<t.length;f++)if((c=t[f])&&(a=c.length))l<a&&(l=a);else if(!r){l=0;break}l?(this.result=wt(t,l,i,e,r,this.h,n),o=!0):this.result=[]}else r||(this.result=t);return n&&(this.await=null),n?this.resolve(i,e,s,h,o):this}P.prototype.xor=function(){return pt(this,"xor",Ae,arguments)};function Ae(t,i,e,s,n,r,h){if(t.length)if(this.result.length&&t.unshift(this.result),t.length<2)this.result=t[0];else{t:{r=e;var o=this.h;const l=[],f=q();let c=0;for(let a=0,m;a<t.length;a++)if(m=t[a]){c<m.length&&(c=m.length);for(let p=0,d;p<m.length;p++)if(d=m[p])for(let u=0,g;u<d.length;u++)g=d[u],f[g]=f[g]?2:1}for(let a=0,m,p=0;a<c;a++)for(let d=0,u;d<t.length;d++)if((u=t[d])&&(m=u[a])){for(let g=0,b;g<m.length;g++)if(b=m[g],f[b]===1)if(r)r--;else if(n){if(l.push(b),l.length===i){t=l;break t}}else{const w=a+(d?o:0);if(l[w]||(l[w]=[]),l[w].push(b),++p===i){t=l;break t}}}t=l}this.result=t,o=!0}else r||(this.result=t);return n&&(this.await=null),n?this.resolve(i,e,s,h,o):this}P.prototype.not=function(){return pt(this,"not",_e,arguments)};function _e(t,i,e,s,n,r,h){if(!r&&!this.result.length)return n?this.result:this;if(t.length&&this.result.length){t:{r=e;var o=[];t=new Set(t.flat().flat());for(let l=0,f,c=0;l<this.result.length;l++)if(f=this.result[l]){for(let a=0,m;a<f.length;a++)if(m=f[a],!t.has(m)){if(r)r--;else if(n){if(o.push(m),o.length===i){t=o;break t}}else if(o[l]||(o[l]=[]),o[l].push(m),++c===i){t=o;break t}}}t=o}this.result=t,o=!0}return n&&(this.await=null),n?this.resolve(i,e,s,h,o):this}function mt(t,i,e,s,n){let r,h,o;typeof n=="string"?(r=n,n=""):r=n.template,h=r.indexOf("$1"),o=r.substring(h+2),h=r.substring(0,h);let l=n&&n.boundary,f=!n||n.clip!==!1,c=n&&n.merge&&o&&h&&new RegExp(o+" "+h,"g");n=n&&n.ellipsis;var a=0;if(typeof n=="object"){var m=n.template;a=m.length-2,n=n.pattern}typeof n!="string"&&(n=n===!1?"":"..."),a&&(n=m.replace("$1",n)),m=n.length-a;let p,d;typeof l=="object"&&(p=l.before,p===0&&(p=-1),d=l.after,d===0&&(d=-1),l=l.total||9e5),a=new Map;for(let Et=0,I,oe,ct;Et<i.length;Et++){let ut;if(s)ut=i,ct=s;else{var u=i[Et];if(ct=u.field,!ct)continue;ut=u.result}oe=e.get(ct),I=oe.encoder,u=a.get(I),typeof u!="string"&&(u=I.encode(t),a.set(I,u));for(let kt=0;kt<ut.length;kt++){var g=ut[kt].doc;if(!g||(g=ht(g,ct),!g))continue;var b=g.trim().split(/\s+/);if(!b.length)continue;g="";var w=[];let At=[];for(var k=-1,B=-1,S=0,j=0;j<b.length;j++){var A=b[j],x=I.encode(A);x=x.length>1?x.join(" "):x[0];let v;if(x&&A){for(var _=A.length,L=(I.split?A.replace(I.split,""):A).length-x.length,C="",$=0,O=0;O<u.length;O++){var N=u[O];if(N){var M=N.length;M+=L<0?0:L,$&&M<=$||(N=x.indexOf(N),N>-1&&(C=(N?A.substring(0,N):"")+h+A.substring(N,N+M)+o+(N+M<_?A.substring(N+M):""),$=M,v=!0))}}C&&(l&&(k<0&&(k=g.length+(g?1:0)),B=g.length+(g?1:0)+C.length,S+=_,At.push(w.length),w.push({match:C})),g+=(g?" ":"")+C)}if(!v)A=b[j],g+=(g?" ":"")+A,l&&w.push({text:A});else if(l&&S>=l)break}if(S=At.length*(r.length-2),p||d||l&&g.length-S>l)if(S=l+S-m*2,j=B-k,p>0&&(j+=p),d>0&&(j+=d),j<=S)b=p?k-(p>0?p:0):k-((S-j)/2|0),w=d?B+(d>0?d:0):b+S,f||(b>0&&g.charAt(b)!==" "&&g.charAt(b-1)!==" "&&(b=g.indexOf(" ",b),b<0&&(b=0)),w<g.length&&g.charAt(w-1)!==" "&&g.charAt(w)!==" "&&(w=g.lastIndexOf(" ",w),w<B?w=B:++w)),g=(b?n:"")+g.substring(b,w)+(w<g.length?n:"");else{for(B=[],k={},S={},j={},A={},x={},C=L=_=0,O=$=1;;){var J=void 0;for(let v=0,D;v<At.length;v++){if(D=At[v],C)if(L!==C){if(j[v+1])continue;if(D+=C,k[D]){_-=m,S[v+1]=1,j[v+1]=1;continue}if(D>=w.length-1){if(D>=w.length){j[v+1]=1,D>=b.length&&(S[v+1]=1);continue}_-=m}if(g=w[D].text,M=d&&x[v])if(M>0){if(g.length>M)if(j[v+1]=1,f)g=g.substring(0,M);else continue;(M-=g.length)||(M=-1),x[v]=M}else{j[v+1]=1;continue}if(_+g.length+1<=l)g=" "+g,B[v]+=g;else if(f)J=l-_-1,J>0&&(g=" "+g.substring(0,J),B[v]+=g),j[v+1]=1;else{j[v+1]=1;continue}}else{if(j[v])continue;if(D-=L,k[D]){_-=m,j[v]=1,S[v]=1;continue}if(D<=0){if(D<0){j[v]=1,S[v]=1;continue}_-=m}if(g=w[D].text,M=p&&A[v])if(M>0){if(g.length>M)if(j[v]=1,f)g=g.substring(g.length-M);else continue;(M-=g.length)||(M=-1),A[v]=M}else{j[v]=1;continue}if(_+g.length+1<=l)g+=" ",B[v]=g+B[v];else if(f)J=g.length+1-(l-_),J>=0&&J<g.length&&(g=g.substring(J)+" ",B[v]=g+B[v]),j[v]=1;else{j[v]=1;continue}}else{g=w[D].match,p&&(A[v]=p),d&&(x[v]=d),v&&_++;let fe;if(D?!v&&m&&(_+=m):(S[v]=1,j[v]=1),D>=b.length-1||D<w.length-1&&w[D+1].match?fe=1:m&&(_+=m),_-=r.length-2,!v||_+g.length<=l)B[v]=g;else{J=$=O=S[v]=0;break}fe&&(S[v+1]=1,j[v+1]=1)}_+=g.length,J=k[D]=1}if(J)L===C?C++:L++;else{if(L===C?$=0:O=0,!$&&!O)break;$?(L++,C=L):C++}}g="";for(let v=0,D;v<B.length;v++)D=(S[v]?v?" ":"":(v&&!n?" ":"")+n)+B[v],g+=D;n&&!S[B.length]&&(g+=n)}c&&(g=g.replace(c," ")),ut[kt].highlight=g}if(s)break}return i}function P(t,i){if(!this||this.constructor!==P)return new P(t,i);let e=0,s,n,r,h,o,l;if(t&&t.index){const f=t;if(i=f.index,e=f.boost||0,n=f.query){r=f.field||f.pluck,h=f.highlight;const c=f.resolve;t=f.async||f.queue,f.resolve=!1,f.index=null,t=t?i.searchAsync(f):i.search(f),f.resolve=c,f.index=i,t=t.result||t}else t=[]}if(t&&t.then){const f=this;t=t.then(function(c){f.C[0]=f.result=c.result||c,zt(f)}),s=[t],t=[],o=new Promise(function(c){l=c})}this.index=i||null,this.result=t||[],this.h=e,this.C=s||[],this.await=o||null,this.return=l||null,this.highlight=h||null,this.query=n||"",this.field=r||""}y=P.prototype,y.limit=function(t){if(this.await){const i=this;this.C.push(function(){return i.limit(t).result})}else if(this.result.length){const i=[];for(let e=0,s;e<this.result.length;e++)if(s=this.result[e])if(s.length<=t){if(i[e]=s,t-=s.length,!t)break}else{i[e]=s.slice(0,t);break}this.result=i}return this},y.offset=function(t){if(this.await){const i=this;this.C.push(function(){return i.offset(t).result})}else if(this.result.length){const i=[];for(let e=0,s;e<this.result.length;e++)(s=this.result[e])&&(s.length<=t?t-=s.length:(i[e]=s.slice(t),t=0));this.result=i}return this},y.boost=function(t){if(this.await){const i=this;this.C.push(function(){return i.boost(t).result})}else this.h+=t;return this};function zt(t,i){let e=t.result;var s=t.await;t.await=null;for(let n=0,r;n<t.C.length;n++)if(r=t.C[n]){if(typeof r=="function")e=r(),t.C[n]=e=e.result||e,n--;else if(r.h)e=r.h(),t.C[n]=e=e.result||e,n--;else if(r.then)return t.await=s}return s=t.return,t.C=[],t.return=null,i||s(e),e}y.resolve=function(t,i,e,s,n){let r=this.await?zt(this,!0):this.result;if(r.then){const h=this;return r.then(function(){return h.resolve(t,i,e,s,n)})}return r.length&&(typeof t=="object"?(s=t.highlight||this.highlight,e=!!s||t.enrich,i=t.offset,t=t.limit):(s=s||this.highlight,e=!!s||e),r=n?e?nt.call(this.index,r):r:qt.call(this.index,r,t||100,i,e)),this.finalize(r,s)},y.finalize=function(t,i){if(t.then){const s=this;return t.then(function(n){return s.finalize(n,i)})}i&&t.length&&this.query&&(t=mt(this.query,t,this.index.index,this.field,i));const e=this.return;return this.highlight=this.index=this.result=this.C=this.await=this.return=null,this.query=this.field="",e&&e(t),t};function wt(t,i,e,s,n,r,h){const o=t.length;let l=[],f,c;f=q();for(let a=0,m,p,d,u;a<i;a++)for(let g=0;g<o;g++)if(d=t[g],a<d.length&&(m=d[a]))for(let b=0;b<m.length;b++){if(p=m[b],(c=f[p])?f[p]++:(c=0,f[p]=1),u=l[c]||(l[c]=[]),!h){let w=a+(g||!n?0:r||0);u=u[w]||(u[w]=[])}if(u.push(p),h&&e&&c===o-1&&u.length-s===e)return s?u.slice(s):u}if(t=l.length)if(n)l=l.length>1?Vt(l,e,s,h,r):(l=l[0])&&e&&l.length>e||s?l.slice(s,e+s):l;else{if(t<o)return[];if(l=l[t-1],e||s)if(h)(l.length>e||s)&&(l=l.slice(s,e+s));else{n=[];for(let a=0,m;a<l.length;a++)if(m=l[a]){if(s&&m.length>s)s-=m.length;else if((e&&m.length>e||s)&&(m=m.slice(s,e+s),e-=m.length,s&&(s-=m.length)),n.push(m),!e)break}l=n}}return l}function Vt(t,i,e,s,n){const r=[],h=q();let o;var l=t.length;let f;if(s){for(n=l-1;n>=0;n--)if(f=(s=t[n])&&s.length){for(l=0;l<f;l++)if(o=s[l],!h[o]){if(h[o]=1,e)e--;else if(r.push(o),r.length===i)return r}}}else for(let c=l-1,a,m=0;c>=0;c--){a=t[c];for(let p=0;p<a.length;p++)if(f=(s=a[p])&&s.length){for(let d=0;d<f;d++)if(o=s[d],!h[o])if(h[o]=1,e)e--;else{let u=(p+(c<l-1&&n||0))/(c+1)|0;if((r[u]||(r[u]=[])).push(o),++m===i)return r}}}return r}function je(t,i,e,s,n){const r=q(),h=[];for(let o=0,l;o<i.length;o++){l=i[o];for(let f=0;f<l.length;f++)r[l[f]]=1}if(n){for(let o=0,l;o<t.length;o++)if(l=t[o],r[l]){if(s)s--;else if(h.push(l),r[l]=0,e&&--e===0)break}}else for(let o=0,l,f;o<t.result.length;o++)for(l=t.result[o],i=0;i<l.length;i++)f=l[i],r[f]&&((h[o]||(h[o]=[])).push(f),r[f]=0);return h}st.prototype.search=function(t,i,e,s){e||(!i&&rt(t)?(e=t,t=""):rt(i)&&(e=i,i=0));let n=[];var r=[];let h,o,l,f,c,a,m=0,p=!0,d;if(e){e.constructor===Array&&(e={index:e}),t=e.query||t,h=e.pluck,o=e.merge,f=e.boost,a=h||e.field||(a=e.index)&&(a.index?null:a);var u=this.tag&&e.tag;l=e.suggest,p=e.resolve!==!1,c=e.cache,d=p&&this.store&&e.highlight;var g=!!d||p&&this.store&&e.enrich;i=e.limit||i;var b=e.offset||0;if(i||(i=p?100:0),u&&(!this.db||!s)){u.constructor!==Array&&(u=[u]);var w=[];for(let A=0,x;A<u.length;A++)if(x=u[A],x.field&&x.tag){var k=x.tag;if(k.constructor===Array)for(var B=0;B<k.length;B++)w.push(x.field,k[B]);else w.push(x.field,k)}else{k=Object.keys(x);for(let _=0,L,C;_<k.length;_++)if(L=k[_],C=x[L],C.constructor===Array)for(B=0;B<C.length;B++)w.push(L,C[B]);else w.push(L,C)}if(u=w,!t){if(r=[],w.length)for(u=0;u<w.length;u+=2){if(this.db){if(s=this.index.get(w[u]),!s)continue;r.push(s=s.db.tag(w[u+1],i,b,g))}else s=Be.call(this,w[u],w[u+1],i,b,g);n.push(p?{field:w[u],tag:w[u+1],result:s}:[s])}if(r.length){const A=this;return Promise.all(r).then(function(x){for(let _=0;_<x.length;_++)p?n[_].result=x[_]:n[_]=x[_];return p?n:new P(n.length>1?wt(n,1,0,0,l,f):n[0],A)})}return p?n:new P(n.length>1?wt(n,1,0,0,l,f):n[0],this)}}p||h||!(a=a||this.field)||(F(a)?h=a:(a.constructor===Array&&a.length===1&&(a=a[0]),h=a.field||a.index)),a&&a.constructor!==Array&&(a=[a])}a||(a=this.field);let S;w=(this.worker||this.db)&&!s&&[];for(let A=0,x,_,L;A<a.length;A++){if(_=a[A],this.db&&this.tag&&!this.B[A])continue;let C;if(F(_)||(C=_,_=C.field,t=C.query||t,i=E(C.limit,i),b=E(C.offset,b),l=E(C.suggest,l),d=p&&this.store&&E(C.highlight,d),g=!!d||p&&this.store&&E(C.enrich,g),c=E(C.cache,c)),s)x=s[A];else{k=C||e||{},B=k.enrich;var j=this.index.get(_);if(u&&(this.db&&(k.tag=u,k.field=a,S=j.db.support_tag_search),!S&&B&&(k.enrich=!1),S||(k.limit=0,k.offset=0)),x=c?j.searchCache(t,u&&!S?0:i,k):j.search(t,u&&!S?0:i,k),u&&!S&&(k.limit=i,k.offset=b),B&&(k.enrich=B),w){w[A]=x;continue}}if(L=(x=x.result||x)&&x.length,u&&L){if(k=[],B=0,this.db&&s){if(!S)for(j=a.length;j<s.length;j++){let $=s[j];if($&&$.length)B++,k.push($);else if(!l)return p?n:new P(n,this)}}else for(let $=0,O,N;$<u.length;$+=2){if(O=this.tag.get(u[$]),!O){if(l)continue;return p?n:new P(n,this)}if(N=(O=O&&O.get(u[$+1]))&&O.length)B++,k.push(O);else if(!l)return p?n:new P(n,this)}if(B){if(x=je(x,k,i,b,p),L=x.length,!L&&!l)return p?x:new P(x,this);B--}}if(L)r[m]=_,n.push(x),m++;else if(a.length===1)return p?n:new P(n,this)}if(w){if(this.db&&u&&u.length&&!S)for(g=0;g<u.length;g+=2){if(r=this.index.get(u[g]),!r){if(l)continue;return p?n:new P(n,this)}w.push(r.db.tag(u[g+1],i,b,!1))}const A=this;return Promise.all(w).then(function(x){return e&&(e.resolve=p),x.length&&(x=A.search(t,i,e,x)),x})}if(!m)return p?n:new P(n,this);if(h&&(!g||!this.store))return n=n[0],p?n:new P(n,this);for(w=[],b=0;b<r.length;b++){if(u=n[b],g&&u.length&&typeof u[0].doc>"u"&&(this.db?w.push(u=this.index.get(this.field[0]).db.enrich(u)):u=nt.call(this,u)),h)return p?d?mt(t,u,this.index,h,d):u:new P(u,this);n[b]={field:r[b],result:u}}if(g&&this.db&&w.length){const A=this;return Promise.all(w).then(function(x){for(let _=0;_<x.length;_++)n[_].result=x[_];return d&&(n=mt(t,n,A.index,h,d)),o?Xt(n):n})}return d&&(n=mt(t,n,this.index,h,d)),o?Xt(n):n};function Xt(t){const i=[],e=q(),s=q();for(let n=0,r,h,o,l,f,c,a;n<t.length;n++){r=t[n],h=r.field,o=r.result;for(let m=0;m<o.length;m++)f=o[m],typeof f!="object"?f={id:l=f}:l=f.id,(c=e[l])?c.push(h):(f.field=e[l]=[h],i.push(f)),(a=f.highlight)&&(c=s[l],c||(s[l]=c={},f.highlight=c),c[h]=a)}return i}function Be(t,i,e,s,n){return t=this.tag.get(t),t?(t=t.get(i),t?(i=t.length-s,i>0&&((e&&i>e||s)&&(t=t.slice(s,s+e)),n&&(t=nt.call(this,t))),t):[]):[]}function nt(t){if(!this||!this.store)return t;if(this.db)return this.index.get(this.field[0]).db.enrich(t);const i=Array(t.length);for(let e=0,s;e<t.length;e++)s=t[e],i[e]={id:s,doc:this.store.get(s)};return i}function st(t){if(!this||this.constructor!==st)return new st(t);const i=t.document||t.doc||t;let e,s;if(this.B=[],this.field=[],this.D=[],this.key=(e=i.key||i.id)&&yt(e,this.D)||"id",(s=t.keystore||0)&&(this.keystore=s),this.fastupdate=!!t.fastupdate,this.reg=!this.fastupdate||t.worker||t.db?s?new K(s):new Set:s?new T(s):new Map,this.h=(e=i.store||null)&&e&&e!==!0&&[],this.store=e?s?new T(s):new Map:null,this.cache=(e=t.cache||null)&&new X(e),t.cache=!1,this.worker=t.worker||!1,this.priority=t.priority||4,this.index=Se.call(this,t,i),this.tag=null,(e=i.tag)&&(typeof e=="string"&&(e=[e]),e.length)){this.tag=new Map,this.A=[],this.F=[];for(let n=0,r,h;n<e.length;n++){if(r=e[n],h=r.field||r,!h)throw Error("The tag field from the document descriptor is undefined.");r.custom?this.A[n]=r.custom:(this.A[n]=yt(h,this.D),r.filter&&(typeof this.A[n]=="string"&&(this.A[n]=new String(this.A[n])),this.A[n].G=r.filter)),this.F[n]=h,this.tag.set(h,new Map)}}if(this.worker){this.fastupdate=!1,t=[];for(const n of this.index.values())n.then&&t.push(n);if(t.length){const n=this;return Promise.all(t).then(function(r){let h=0;for(const o of n.index.entries()){const l=o[0];let f=o[1];f.then&&(f=r[h],n.index.set(l,f),h++)}return n})}}else t.db&&(this.fastupdate=!1,this.mount(t.db))}y=st.prototype,y.mount=function(t){let i=this.field;if(this.tag)for(let r=0,h;r<this.F.length;r++){h=this.F[r];var e=void 0;this.index.set(h,e=new G({},this.reg)),i===this.field&&(i=i.slice(0)),i.push(h),e.tag=this.tag.get(h)}e=[];const s={db:t.db,type:t.type,fastupdate:t.fastupdate};for(let r=0,h,o;r<i.length;r++){s.field=o=i[r],h=this.index.get(o);const l=new t.constructor(t.id,s);l.id=t.id,e[r]=l.mount(h),h.document=!0,r?h.bypass=!0:h.store=this.store}const n=this;return this.db=Promise.all(e).then(function(){n.db=!0})},y.commit=async function(){const t=[];for(const i of this.index.values())t.push(i.commit());await Promise.all(t),this.reg.clear()},y.destroy=function(){const t=[];for(const i of this.index.values())t.push(i.destroy());return Promise.all(t)};function Se(t,i){const e=new Map;let s=i.index||i.field||i;F(s)&&(s=[s]);for(let r=0,h,o;r<s.length;r++){if(h=s[r],F(h)||(o=h,h=h.field),o=rt(o)?Object.assign({},t,o):t,this.worker){var n=void 0;n=(n=o.encoder)&&n.encode?n:new lt(typeof n=="string"?Wt[n]:n||{}),n=new it(o,n),e.set(h,n)}this.worker||e.set(h,new G(o,this.reg)),o.custom?this.B[r]=o.custom:(this.B[r]=yt(h,this.D),o.filter&&(typeof this.B[r]=="string"&&(this.B[r]=new String(this.B[r])),this.B[r].G=o.filter)),this.field[r]=h}if(this.h){t=i.store,F(t)&&(t=[t]);for(let r=0,h,o;r<t.length;r++)h=t[r],o=h.field||h,h.custom?(this.h[r]=h.custom,h.custom.O=o):(this.h[r]=yt(o,this.D),h.filter&&(typeof this.h[r]=="string"&&(this.h[r]=new String(this.h[r])),this.h[r].G=h.filter))}return e}function yt(t,i){const e=t.split(":");let s=0;for(let n=0;n<e.length;n++)t=e[n],t[t.length-1]==="]"&&(t=t.substring(0,t.length-2))&&(i[s]=!0),t&&(e[s++]=t);return s<e.length&&(e.length=s),s>1?e:e[0]}y.append=function(t,i){return this.add(t,i,!0)},y.update=function(t,i){return this.remove(t).add(t,i)},y.remove=function(t){rt(t)&&(t=ht(t,this.key));for(var i of this.index.values())i.remove(t,!0);if(this.reg.has(t)){if(this.tag&&!this.fastupdate)for(let e of this.tag.values())for(let s of e){i=s[0];const n=s[1],r=n.indexOf(t);r>-1&&(n.length>1?n.splice(r,1):e.delete(i))}this.store&&this.store.delete(t),this.reg.delete(t)}return this.cache&&this.cache.remove(t),this},y.clear=function(){const t=[];for(const i of this.index.values()){const e=i.clear();e.then&&t.push(e)}if(this.tag)for(const i of this.tag.values())i.clear();return this.store&&this.store.clear(),this.cache&&this.cache.clear(),t.length?Promise.all(t):this},y.contain=function(t){return this.db?this.index.get(this.field[0]).db.has(t):this.reg.has(t)},y.cleanup=function(){for(const t of this.index.values())t.cleanup();return this},y.get=function(t){return this.db?this.index.get(this.field[0]).db.enrich(t).then(function(i){return i[0]&&i[0].doc||null}):this.store.get(t)||null},y.set=function(t,i){return typeof t=="object"&&(i=t,t=ht(i,this.key)),this.store.set(t,i),this},y.searchCache=_t,y.export=Ce,y.import=Pe,Bt(st.prototype);function Lt(t,i=0){let e=[],s=[];i&&(i=25e4/i*5e3|0);for(const n of t.entries())s.push(n),s.length===i&&(e.push(s),s=[]);return s.length&&e.push(s),e}function Dt(t,i){i||(i=new Map);for(let e=0,s;e<t.length;e++)s=t[e],i.set(s[0],s[1]);return i}function Yt(t,i=0){let e=[],s=[];i&&(i=25e4/i*1e3|0);for(const n of t.entries())s.push([n[0],Lt(n[1])[0]||[]]),s.length===i&&(e.push(s),s=[]);return s.length&&e.push(s),e}function It(t,i){i||(i=new Map);for(let e=0,s,n;e<t.length;e++)s=t[e],n=i.get(s[0]),i.set(s[0],Dt(s[1],n));return i}function Ht(t){let i=[],e=[];for(const s of t.keys())e.push(s),e.length===25e4&&(i.push(e),e=[]);return e.length&&i.push(e),i}function te(t,i){i||(i=new Set);for(let e=0;e<t.length;e++)i.add(t[e]);return i}function bt(t,i,e,s,n,r,h=0){const o=s&&s.constructor===Array;var l=o?s.shift():s;if(!l)return this.export(t,i,n,r+1);if((l=t((i?i+".":"")+(h+1)+"."+e,JSON.stringify(l)))&&l.then){const f=this;return l.then(function(){return bt.call(f,t,i,e,o?s:null,n,r,h+1)})}return bt.call(this,t,i,e,o?s:null,n,r,h+1)}function Ce(t,i,e=0,s=0){if(e<this.field.length){const h=this.field[e];if((i=this.index.get(h).export(t,h,e,s=1))&&i.then){const o=this;return i.then(function(){return o.export(t,h,e+1)})}return this.export(t,h,e+1)}let n,r;switch(s){case 0:n="reg",r=Ht(this.reg),i=null;break;case 1:n="tag",r=this.tag&&Yt(this.tag,this.reg.size),i=null;break;case 2:n="doc",r=this.store&&Lt(this.store),i=null;break;default:return}return bt.call(this,t,i,n,r||null,e,s)}function Pe(t,i){var e=t.split(".");e[e.length-1]==="json"&&e.pop();const s=e.length>2?e[0]:"";if(e=e.length>2?e[2]:e[1],this.worker&&s)return this.index.get(s).import(t);if(i){if(typeof i=="string"&&(i=JSON.parse(i)),s)return this.index.get(s).import(e,i);switch(e){case"reg":this.fastupdate=!1,this.reg=te(i,this.reg);for(let n=0,r;n<this.field.length;n++)r=this.index.get(this.field[n]),r.fastupdate=!1,r.reg=this.reg;if(this.worker){i=[];for(const n of this.index.values())i.push(n.import(t));return Promise.all(i)}break;case"tag":this.tag=It(i,this.tag);break;case"doc":this.store=Dt(i,this.store)}}}function ee(t,i){let e="";for(const s of t.entries()){t=s[0];const n=s[1];let r="";for(let h=0,o;h<n.length;h++){o=n[h]||[""];let l="";for(let f=0;f<o.length;f++)l+=(l?",":"")+(i==="string"?'"'+o[f]+'"':o[f]);l="["+l+"]",r+=(r?",":"")+l}r='["'+t+'",['+r+"]]",e+=(e?",":"")+r}return e}G.prototype.remove=function(t,i){const e=this.reg.size&&(this.fastupdate?this.reg.get(t):this.reg.has(t));if(e){if(this.fastupdate){for(let s=0,n,r;s<e.length;s++)if((n=e[s])&&(r=n.length))if(n[r-1]===t)n.pop();else{const h=n.indexOf(t);h>=0&&n.splice(h,1)}}else ft(this.map,t),this.depth&&ft(this.ctx,t);i||this.reg.delete(t)}return this.db&&(this.commit_task.push({del:t}),this.M&&re(this)),this.cache&&this.cache.remove(t),this};function ft(t,i){let e=0;var s=typeof i>"u";if(t.constructor===Array){for(let n=0,r,h,o;n<t.length;n++)if((r=t[n])&&r.length){if(s)return 1;if(h=r.indexOf(i),h>=0){if(r.length>1)return r.splice(h,1),1;if(delete t[n],e)return 1;o=1}else{if(o)return 1;e++}}}else for(let n of t.entries())s=n[0],ft(n[1],i)?e++:t.delete(s);return e}const qe={memory:{resolution:1},performance:{resolution:3,fastupdate:!0,context:{depth:1,resolution:1}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:3}}};G.prototype.add=function(t,i,e,s){if(i&&(t||t===0)){if(!s&&!e&&this.reg.has(t))return this.update(t,i);s=this.depth,i=this.encoder.encode(i,!s);const f=i.length;if(f){const c=q(),a=q(),m=this.resolution;for(let p=0;p<f;p++){let d=i[this.rtl?f-1-p:p];var n=d.length;if(n&&(s||!a[d])){var r=this.score?this.score(i,d,p,null,0):xt(m,f,p),h="";switch(this.tokenize){case"tolerant":if(W(this,a,d,r,t,e),n>2){for(let u=1,g,b,w,k;u<n-1;u++)g=d.charAt(u),b=d.charAt(u+1),w=d.substring(0,u)+b,k=d.substring(u+2),h=w+g+k,W(this,a,h,r,t,e),h=w+k,W(this,a,h,r,t,e);W(this,a,d.substring(0,d.length-1),r,t,e)}break;case"full":if(n>2){for(let u=0,g;u<n;u++)for(r=n;r>u;r--){h=d.substring(u,r),g=this.rtl?n-1-u:u;var o=this.score?this.score(i,d,p,h,g):xt(m,f,p,n,g);W(this,a,h,o,t,e)}break}case"bidirectional":case"reverse":if(n>1){for(o=n-1;o>0;o--){h=d[this.rtl?n-1-o:o]+h;var l=this.score?this.score(i,d,p,h,o):xt(m,f,p,n,o);W(this,a,h,l,t,e)}h=""}case"forward":if(n>1){for(o=0;o<n;o++)h+=d[this.rtl?n-1-o:o],W(this,a,h,r,t,e);break}default:if(W(this,a,d,r,t,e),s&&f>1&&p<f-1)for(n=this.N,h=d,r=Math.min(s+1,this.rtl?p+1:f-p),o=1;o<r;o++){d=i[this.rtl?f-1-p-o:p+o],l=this.bidirectional&&d>h;const u=this.score?this.score(i,h,p,d,o-1):xt(n+(f/2>n?0:1),f,p,r-1,o-1);W(this,c,l?h:d,u,t,e,l?d:h)}}}}this.fastupdate||this.reg.add(t)}}return this.db&&(this.commit_task.push(e?{ins:t}:{del:t}),this.M&&re(this)),this};function W(t,i,e,s,n,r,h){let o,l;if(!(o=i[e])||h&&!o[h]){if(h?(i=o||(i[e]=q()),i[h]=1,l=t.ctx,(o=l.get(h))?l=o:l.set(h,l=t.keystore?new T(t.keystore):new Map)):(l=t.map,i[e]=1),(o=l.get(e))?l=o:l.set(e,l=o=[]),r){for(let f=0,c;f<o.length;f++)if((c=o[f])&&c.includes(n)){if(f<=s)return;c.splice(c.indexOf(n),1),t.fastupdate&&(i=t.reg.get(n))&&i.splice(i.indexOf(c),1);break}}if(l=l[s]||(l[s]=[]),l.push(n),l.length===2**31-1){if(i=new H(l),t.fastupdate)for(let f of t.reg.values())f.includes(l)&&(f[f.indexOf(l)]=i);o[s]=l=i}t.fastupdate&&((s=t.reg.get(n))?s.push(l):t.reg.set(n,[l]))}}function xt(t,i,e,s,n){return e&&t>1?i+(s||0)<=t?e+(n||0):(t-1)/(i+(s||0))*(e+(n||0))+1|0:0}G.prototype.search=function(t,i,e){if(e||(i||typeof t!="object"?typeof i=="object"&&(e=i,i=0):(e=t,t="")),e&&e.cache)return e.cache=!1,t=this.searchCache(t,i,e),e.cache=!0,t;let s=[],n,r,h,o=0,l,f,c,a,m;e&&(t=e.query||t,i=e.limit||i,o=e.offset||0,r=e.context,h=e.suggest,m=(l=e.resolve)&&e.enrich,c=e.boost,a=e.resolution,f=this.db&&e.tag),typeof l>"u"&&(l=this.resolve),r=this.depth&&r!==!1;let p=this.encoder.encode(t,!r);if(n=p.length,i=i||(l?100:0),n===1)return ne.call(this,p[0],"",i,o,l,m,f);if(n===2&&r&&!h)return ne.call(this,p[1],p[0],i,o,l,m,f);let d=q(),u=0,g;if(r&&(g=p[0],u=1),a||a===0||(a=g?this.N:this.resolution),this.db){if(this.db.search&&(e=this.db.search(this,p,i,o,h,l,m,f),e!==!1))return e;const b=this;return async function(){for(let w,k;u<n;u++){if((k=p[u])&&!d[k]){if(d[k]=1,w=await Mt(b,k,g,0,0,!1,!1),w=se(w,s,h,a)){s=w;break}g&&(h&&w&&s.length||(g=k))}h&&g&&u===n-1&&!s.length&&(a=b.resolution,g="",u=-1,d=q())}return ie(s,a,i,o,h,c,l)}()}for(let b,w;u<n;u++){if((w=p[u])&&!d[w]){if(d[w]=1,b=Mt(this,w,g,0,0,!1,!1),b=se(b,s,h,a)){s=b;break}g&&(h&&b&&s.length||(g=w))}h&&g&&u===n-1&&!s.length&&(a=this.resolution,g="",u=-1,d=q())}return ie(s,a,i,o,h,c,l)};function ie(t,i,e,s,n,r,h){let o=t.length,l=t;if(o>1)l=wt(t,i,e,s,n,r,h);else if(o===1)return h?qt.call(null,t[0],e,s):new P(t[0],this);return h?l:new P(l,this)}function ne(t,i,e,s,n,r,h){return t=Mt(this,t,i,e,s,n,r,h),this.db?t.then(function(o){return n?o||[]:new P(o,this)}):t&&t.length?n?qt.call(this,t,e,s):new P(t,this):n?[]:new P([],this)}function se(t,i,e,s){let n=[];if(t&&t.length){if(t.length<=s){i.push(t);return}for(let r=0,h;r<s;r++)(h=t[r])&&(n[r]=h);if(n.length){i.push(n);return}}if(!e)return n}function Mt(t,i,e,s,n,r,h,o){let l;return e&&(l=t.bidirectional&&i>e)&&(l=e,e=i,i=l),t.db?t.db.get(i,e,s,n,r,h,o):(t=e?(t=t.ctx.get(e))&&t.get(i):t.map.get(i),t)}function G(t,i){if(!this||this.constructor!==G)return new G(t);if(t){var e=F(t)?t:t.preset;e&&(t=Object.assign({},qe[e],t))}else t={};e=t.context;const s=e===!0?{depth:1}:e||{},n=F(t.encoder)?Wt[t.encoder]:t.encode||t.encoder||{};this.encoder=n.encode?n:typeof n=="object"?new lt(n):{encode:n},this.resolution=t.resolution||9,this.tokenize=e=(e=t.tokenize)&&e!=="default"&&e!=="exact"&&e||"strict",this.depth=e==="strict"&&s.depth||0,this.bidirectional=s.bidirectional!==!1,this.fastupdate=!!t.fastupdate,this.score=t.score||null,(e=t.keystore||0)&&(this.keystore=e),this.map=e?new T(e):new Map,this.ctx=e?new T(e):new Map,this.reg=i||(this.fastupdate?e?new T(e):new Map:e?new K(e):new Set),this.N=s.resolution||3,this.rtl=n.rtl||t.rtl||!1,this.cache=(e=t.cache||null)&&new X(e),this.resolve=t.resolve!==!1,(e=t.db)&&(this.db=this.mount(e)),this.M=t.commit!==!1,this.commit_task=[],this.commit_timer=null,this.priority=t.priority||4}y=G.prototype,y.mount=function(t){return this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null),t.mount(this)},y.commit=function(){return this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null),this.db.commit(this)},y.destroy=function(){return this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null),this.db.destroy()};function re(t){t.commit_timer||(t.commit_timer=setTimeout(function(){t.commit_timer=null,t.db.commit(t)},1))}y.clear=function(){return this.map.clear(),this.ctx.clear(),this.reg.clear(),this.cache&&this.cache.clear(),this.db?(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[],this.db.clear()):this},y.append=function(t,i){return this.add(t,i,!0)},y.contain=function(t){return this.db?this.db.has(t):this.reg.has(t)},y.update=function(t,i){const e=this,s=this.remove(t);return s&&s.then?s.then(()=>e.add(t,i)):this.add(t,i)},y.cleanup=function(){return this.fastupdate?(ft(this.map),this.depth&&ft(this.ctx),this):this},y.searchCache=_t,y.export=function(t,i,e=0,s=0){let n,r;switch(s){case 0:n="reg",r=Ht(this.reg);break;case 1:n="cfg",r=null;break;case 2:n="map",r=Lt(this.map,this.reg.size);break;case 3:n="ctx",r=Yt(this.ctx,this.reg.size);break;default:return}return bt.call(this,t,i,n,r,e,s)},y.import=function(t,i){if(i)switch(typeof i=="string"&&(i=JSON.parse(i)),t=t.split("."),t[t.length-1]==="json"&&t.pop(),t.length===3&&t.shift(),t=t.length>1?t[1]:t[0],t){case"reg":this.fastupdate=!1,this.reg=te(i,this.reg);break;case"map":this.map=Dt(i,this.map);break;case"ctx":this.ctx=It(i,this.ctx)}},y.serialize=function(t=!0){let i="",e="",s="";if(this.reg.size){let r;for(var n of this.reg.keys())r||(r=typeof n),i+=(i?",":"")+(r==="string"?'"'+n+'"':n);i="index.reg=new Set(["+i+"]);",e=ee(this.map,r),e="index.map=new Map(["+e+"]);";for(const h of this.ctx.entries()){n=h[0];let o=ee(h[1],r);o="new Map(["+o+"])",o='["'+n+'",'+o+"]",s+=(s?",":"")+o}s="index.ctx=new Map(["+s+"]);"}return t?"function inject(index){"+i+e+s+"}":i+e+s},Bt(G.prototype);const he=typeof window<"u"&&(window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB),vt=["map","ctx","tag","reg","cfg"],Y=q();function $t(t,i={}){if(!this||this.constructor!==$t)return new $t(t,i);typeof t=="object"&&(i=t,t=t.name),t||console.info("Default storage space was used, because a name was not passed."),this.id="flexsearch"+(t?":"+t.toLowerCase().replace(/[^a-z0-9_\-]/g,""):""),this.field=i.field?i.field.toLowerCase().replace(/[^a-z0-9_\-]/g,""):"",this.type=i.type,this.fastupdate=this.support_tag_search=!1,this.db=null,this.h={}}y=$t.prototype,y.mount=function(t){return t.index?t.mount(this):(t.db=this,this.open())},y.open=function(){if(this.db)return this.db;let t=this;navigator.storage&&navigator.storage.persist&&navigator.storage.persist(),Y[t.id]||(Y[t.id]=[]),Y[t.id].push(t.field);const i=he.open(t.id,1);return i.onupgradeneeded=function(){const e=t.db=this.result;for(let s=0,n;s<vt.length;s++){n=vt[s];for(let r=0,h;r<Y[t.id].length;r++)h=Y[t.id][r],e.objectStoreNames.contains(n+(n!=="reg"&&h?":"+h:""))||e.createObjectStore(n+(n!=="reg"&&h?":"+h:""))}},t.db=Z(i,function(e){t.db=e,t.db.onversionchange=function(){t.close()}})},y.close=function(){this.db&&this.db.close(),this.db=null},y.destroy=function(){const t=he.deleteDatabase(this.id);return Z(t)},y.clear=function(){const t=[];for(let e=0,s;e<vt.length;e++){s=vt[e];for(let n=0,r;n<Y[this.id].length;n++)r=Y[this.id][n],t.push(s+(s!=="reg"&&r?":"+r:""))}const i=this.db.transaction(t,"readwrite");for(let e=0;e<t.length;e++)i.objectStore(t[e]).clear();return Z(i)},y.get=function(t,i,e=0,s=0,n=!0,r=!1){t=this.db.transaction((i?"ctx":"map")+(this.field?":"+this.field:""),"readonly").objectStore((i?"ctx":"map")+(this.field?":"+this.field:"")).get(i?i+":"+t:t);const h=this;return Z(t).then(function(o){let l=[];if(!o||!o.length)return l;if(n){if(!e&&!s&&o.length===1)return o[0];for(let f=0,c;f<o.length;f++)if((c=o[f])&&c.length){if(s>=c.length){s-=c.length;continue}const a=e?s+Math.min(c.length-s,e):c.length;for(let m=s;m<a;m++)l.push(c[m]);if(s=0,l.length===e)break}return r?h.enrich(l):l}return o})},y.tag=function(t,i=0,e=0,s=!1){t=this.db.transaction("tag"+(this.field?":"+this.field:""),"readonly").objectStore("tag"+(this.field?":"+this.field:"")).get(t);const n=this;return Z(t).then(function(r){return!r||!r.length||e>=r.length?[]:!i&&!e?r:(r=r.slice(e,e+i),s?n.enrich(r):r)})},y.enrich=function(t){typeof t!="object"&&(t=[t]);const i=this.db.transaction("reg","readonly").objectStore("reg"),e=[];for(let s=0;s<t.length;s++)e[s]=Z(i.get(t[s]));return Promise.all(e).then(function(s){for(let n=0;n<s.length;n++)s[n]={id:t[n],doc:s[n]?JSON.parse(s[n]):null};return s})},y.has=function(t){return t=this.db.transaction("reg","readonly").objectStore("reg").getKey(t),Z(t).then(function(i){return!!i})},y.search=null,y.info=function(){},y.transaction=function(t,i,e){t+=t!=="reg"&&this.field?":"+this.field:"";let s=this.h[t+":"+i];if(s)return e.call(this,s);let n=this.db.transaction(t,i);this.h[t+":"+i]=s=n.objectStore(t);const r=e.call(this,s);return this.h[t+":"+i]=null,Z(n).finally(function(){return r})},y.commit=async function(t){let i=t.commit_task,e=[];t.commit_task=[];for(let s=0,n;s<i.length;s++)n=i[s],n.del&&e.push(n.del);e.length&&await this.remove(e),t.reg.size&&(await this.transaction("map","readwrite",function(s){for(const n of t.map){const r=n[0],h=n[1];h.length&&(s.get(r).onsuccess=function(){let o=this.result;var l;if(o&&o.length){const f=Math.max(o.length,h.length);for(let c=0,a,m;c<f;c++)if((m=h[c])&&m.length){if((a=o[c])&&a.length)for(l=0;l<m.length;l++)a.push(m[l]);else o[c]=m;l=1}}else o=h,l=1;l&&s.put(o,r)})}}),await this.transaction("ctx","readwrite",function(s){for(const n of t.ctx){const r=n[0],h=n[1];for(const o of h){const l=o[0],f=o[1];f.length&&(s.get(r+":"+l).onsuccess=function(){let c=this.result;var a;if(c&&c.length){const m=Math.max(c.length,f.length);for(let p=0,d,u;p<m;p++)if((u=f[p])&&u.length){if((d=c[p])&&d.length)for(a=0;a<u.length;a++)d.push(u[a]);else c[p]=u;a=1}}else c=f,a=1;a&&s.put(c,r+":"+l)})}}}),t.store?await this.transaction("reg","readwrite",function(s){for(const n of t.store){const r=n[0],h=n[1];s.put(typeof h=="object"?JSON.stringify(h):1,r)}}):t.bypass||await this.transaction("reg","readwrite",function(s){for(const n of t.reg.keys())s.put(1,n)}),t.tag&&await this.transaction("tag","readwrite",function(s){for(const n of t.tag){const r=n[0],h=n[1];h.length&&(s.get(r).onsuccess=function(){let o=this.result;o=o&&o.length?o.concat(h):h,s.put(o,r)})}}),t.map.clear(),t.ctx.clear(),t.tag&&t.tag.clear(),t.store&&t.store.clear(),t.document||t.reg.clear())};function Ot(t,i,e){const s=t.value;let n,r=0;for(let h=0,o;h<s.length;h++){if(o=e?s:s[h]){for(let l=0,f,c;l<i.length;l++)if(c=i[l],f=o.indexOf(c),f>=0)if(n=1,o.length>1)o.splice(f,1);else{s[h]=[];break}r+=o.length}if(e)break}r?n&&t.update(s):t.delete(),t.continue()}y.remove=function(t){return typeof t!="object"&&(t=[t]),Promise.all([this.transaction("map","readwrite",function(i){i.openCursor().onsuccess=function(){const e=this.result;e&&Ot(e,t)}}),this.transaction("ctx","readwrite",function(i){i.openCursor().onsuccess=function(){const e=this.result;e&&Ot(e,t)}}),this.transaction("tag","readwrite",function(i){i.openCursor().onsuccess=function(){const e=this.result;e&&Ot(e,t,!0)}}),this.transaction("reg","readwrite",function(i){for(let e=0;e<t.length;e++)i.delete(t[e])})])};function Z(t,i){return new Promise((e,s)=>{t.onsuccess=t.oncomplete=function(){i&&i(this.result),i=null,e(this.result)},t.onerror=t.onblocked=s,t=null})}const le=G;let Nt=new le;self.onmessage=t=>{switch(t.data.type){case"clear":Nt=new le,postMessage({identifier:t.data.identifier});break;case"points":for(let e of t.data.points)Nt.add(e.id,e.text);postMessage({identifier:t.data.identifier});break;case"query":let i=Nt.search(t.data.query,{limit:t.data.limit});postMessage({identifier:t.data.identifier,result:i});break}}})()})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"
|
|
1
|
+
{"version":"1759479212790"}
|
|
@@ -5,35 +5,35 @@
|
|
|
5
5
|
<link rel="icon" href="/favicon.png" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
7
7
|
|
|
8
|
-
<link rel="modulepreload" href="/_app/immutable/entry/start.
|
|
9
|
-
<link rel="modulepreload" href="/_app/immutable/chunks/
|
|
10
|
-
<link rel="modulepreload" href="/_app/immutable/chunks/
|
|
8
|
+
<link rel="modulepreload" href="/_app/immutable/entry/start.u7zsVvqp.js">
|
|
9
|
+
<link rel="modulepreload" href="/_app/immutable/chunks/DEgUu98i.js">
|
|
10
|
+
<link rel="modulepreload" href="/_app/immutable/chunks/CH6P3X75.js">
|
|
11
11
|
<link rel="modulepreload" href="/_app/immutable/chunks/DIeogL5L.js">
|
|
12
12
|
<link rel="modulepreload" href="/_app/immutable/chunks/CYgJF_JY.js">
|
|
13
|
-
<link rel="modulepreload" href="/_app/immutable/entry/app.
|
|
14
|
-
<link rel="modulepreload" href="/_app/immutable/chunks/
|
|
15
|
-
<link rel="modulepreload" href="/_app/immutable/chunks/
|
|
16
|
-
<link rel="modulepreload" href="/_app/immutable/chunks/
|
|
13
|
+
<link rel="modulepreload" href="/_app/immutable/entry/app.BVr6DYqP.js">
|
|
14
|
+
<link rel="modulepreload" href="/_app/immutable/chunks/DQXoLcsF.js">
|
|
15
|
+
<link rel="modulepreload" href="/_app/immutable/chunks/DA6bFLPR.js">
|
|
16
|
+
<link rel="modulepreload" href="/_app/immutable/chunks/BfHVnyNT.js">
|
|
17
17
|
<link rel="modulepreload" href="/_app/immutable/chunks/CWj6FrbW.js">
|
|
18
18
|
<link rel="modulepreload" href="/_app/immutable/chunks/69_IOA4Y.js">
|
|
19
|
-
<link rel="modulepreload" href="/_app/immutable/chunks/
|
|
20
|
-
<link rel="modulepreload" href="/_app/immutable/chunks/
|
|
21
|
-
<link rel="modulepreload" href="/_app/immutable/chunks/
|
|
22
|
-
<link rel="modulepreload" href="/_app/immutable/chunks/
|
|
19
|
+
<link rel="modulepreload" href="/_app/immutable/chunks/Cs1XmhiF.js">
|
|
20
|
+
<link rel="modulepreload" href="/_app/immutable/chunks/DGTPl6Gk.js">
|
|
21
|
+
<link rel="modulepreload" href="/_app/immutable/chunks/D4whDBUi.js">
|
|
22
|
+
<link rel="modulepreload" href="/_app/immutable/chunks/RmD8FzRo.js">
|
|
23
23
|
</head>
|
|
24
24
|
<body data-sveltekit-preload-data="hover" class="flex h-screen w-screen flex-col dark:bg-black">
|
|
25
25
|
<div style="display: contents">
|
|
26
26
|
<script>
|
|
27
27
|
{
|
|
28
|
-
|
|
28
|
+
__sveltekit_1gqf9ui = {
|
|
29
29
|
base: ""
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
const element = document.currentScript.parentElement;
|
|
33
33
|
|
|
34
34
|
Promise.all([
|
|
35
|
-
import("/_app/immutable/entry/start.
|
|
36
|
-
import("/_app/immutable/entry/app.
|
|
35
|
+
import("/_app/immutable/entry/start.u7zsVvqp.js"),
|
|
36
|
+
import("/_app/immutable/entry/app.BVr6DYqP.js")
|
|
37
37
|
]).then(([kit, app]) => {
|
|
38
38
|
kit.start(app, element);
|
|
39
39
|
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Exports datasets from Lightly Studio into various formats."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Iterable
|
|
5
|
+
|
|
6
|
+
from labelformat.formats import COCOObjectDetectionOutput
|
|
7
|
+
from sqlmodel import Session
|
|
8
|
+
|
|
9
|
+
from lightly_studio.core.sample import Sample
|
|
10
|
+
from lightly_studio.export.lightly_studio_label_input import LightlyStudioObjectDetectionInput
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class DatasetExport:
|
|
14
|
+
"""Provides methods to export a dataset or a subset of it.
|
|
15
|
+
|
|
16
|
+
This class is typically not instantiated directly but returned by `Dataset.export()`.
|
|
17
|
+
It allows exporting data in various formats.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def __init__(self, session: Session, samples: Iterable[Sample]):
|
|
21
|
+
"""Initializes the DatasetExport object.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
session: The database session.
|
|
25
|
+
samples: Samples to export.
|
|
26
|
+
"""
|
|
27
|
+
self.session = session
|
|
28
|
+
self.samples = samples
|
|
29
|
+
|
|
30
|
+
def to_coco_object_detections(self, output_json: Path) -> None:
|
|
31
|
+
"""Exports object detection annotations to a COCO format JSON file.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
output_json: The path to the output COCO JSON file.
|
|
35
|
+
|
|
36
|
+
Raises:
|
|
37
|
+
ValueError: If the annotation task with the given name does not exist.
|
|
38
|
+
"""
|
|
39
|
+
to_coco_object_detections(
|
|
40
|
+
session=self.session,
|
|
41
|
+
samples=self.samples,
|
|
42
|
+
output_json=output_json,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def to_coco_object_detections(
|
|
47
|
+
session: Session,
|
|
48
|
+
samples: Iterable[Sample],
|
|
49
|
+
output_json: Path,
|
|
50
|
+
) -> None:
|
|
51
|
+
"""Exports object detection annotations to a COCO format JSON file.
|
|
52
|
+
|
|
53
|
+
This function is for internal use. Use `Dataset.query().export().to_coco_object_detections()`
|
|
54
|
+
instead.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
session: The database session.
|
|
58
|
+
samples: The samples to export.
|
|
59
|
+
output_json: The path to save the output JSON file.
|
|
60
|
+
"""
|
|
61
|
+
export_input = LightlyStudioObjectDetectionInput(
|
|
62
|
+
session=session,
|
|
63
|
+
samples=samples,
|
|
64
|
+
)
|
|
65
|
+
COCOObjectDetectionOutput(output_file=output_json).save(label_input=export_input)
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""Converts annotations from Lightly Studio to Labelformat format."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from argparse import ArgumentParser
|
|
6
|
+
from typing import Iterable
|
|
7
|
+
from uuid import UUID
|
|
8
|
+
|
|
9
|
+
from labelformat.model.bounding_box import BoundingBox
|
|
10
|
+
from labelformat.model.category import Category
|
|
11
|
+
from labelformat.model.image import Image
|
|
12
|
+
from labelformat.model.object_detection import (
|
|
13
|
+
ImageObjectDetection,
|
|
14
|
+
ObjectDetectionInput,
|
|
15
|
+
SingleObjectDetection,
|
|
16
|
+
)
|
|
17
|
+
from sqlmodel import Session
|
|
18
|
+
|
|
19
|
+
from lightly_studio.core.sample import Sample
|
|
20
|
+
from lightly_studio.models.annotation.annotation_base import AnnotationBaseTable, AnnotationType
|
|
21
|
+
from lightly_studio.resolvers import annotation_label_resolver
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class LightlyStudioObjectDetectionInput(ObjectDetectionInput):
|
|
25
|
+
"""Labelformat adapter backed by dataset samples and annotations."""
|
|
26
|
+
|
|
27
|
+
def __init__(self, session: Session, samples: Iterable[Sample]) -> None:
|
|
28
|
+
"""Initializes the LightlyStudioObjectDetectionInput.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
session: The SQLModel session to use for database access. Used only in the
|
|
32
|
+
constructor to fetch the labels for the given annotation task.
|
|
33
|
+
samples: Dataset samples.
|
|
34
|
+
"""
|
|
35
|
+
self._samples = list(samples)
|
|
36
|
+
self._label_id_to_category = _build_label_id_to_category(session=session)
|
|
37
|
+
|
|
38
|
+
@staticmethod
|
|
39
|
+
def add_cli_arguments(parser: ArgumentParser) -> None:
|
|
40
|
+
"""Adds CLI arguments."""
|
|
41
|
+
# Add CLI arguments implementation is not needed for this class. We need it only
|
|
42
|
+
# to satisfy the interface.
|
|
43
|
+
raise NotImplementedError()
|
|
44
|
+
|
|
45
|
+
def get_categories(self) -> Iterable[Category]:
|
|
46
|
+
"""Returns the categories for export."""
|
|
47
|
+
return self._label_id_to_category.values()
|
|
48
|
+
|
|
49
|
+
def get_images(self) -> Iterable[Image]:
|
|
50
|
+
"""Returns the images for export."""
|
|
51
|
+
for idx, sample in enumerate(self._samples):
|
|
52
|
+
yield _sample_to_image(sample=sample, image_id=idx)
|
|
53
|
+
|
|
54
|
+
def get_labels(self) -> Iterable[ImageObjectDetection]:
|
|
55
|
+
"""Returns the labels for export."""
|
|
56
|
+
for idx, sample in enumerate(self._samples):
|
|
57
|
+
yield _sample_to_image_obj_det(
|
|
58
|
+
sample=sample,
|
|
59
|
+
image_id=idx,
|
|
60
|
+
label_id_to_category=self._label_id_to_category,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _build_label_id_to_category(session: Session) -> dict[UUID, Category]:
|
|
65
|
+
labels = annotation_label_resolver.get_all_sorted_alphabetically(
|
|
66
|
+
session=session,
|
|
67
|
+
)
|
|
68
|
+
# TODO(Horatiu, 09/2025): We should get only labels that are attached to Object Detection
|
|
69
|
+
# annotations.
|
|
70
|
+
return {
|
|
71
|
+
label.annotation_label_id: Category(id=idx, name=label.annotation_label_name)
|
|
72
|
+
for idx, label in enumerate(labels)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _sample_to_image(sample: Sample, image_id: int) -> Image:
|
|
77
|
+
return Image(
|
|
78
|
+
id=image_id,
|
|
79
|
+
filename=sample.file_path_abs,
|
|
80
|
+
width=sample.width,
|
|
81
|
+
height=sample.height,
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _sample_to_image_obj_det(
|
|
86
|
+
sample: Sample,
|
|
87
|
+
image_id: int,
|
|
88
|
+
label_id_to_category: dict[UUID, Category],
|
|
89
|
+
) -> ImageObjectDetection:
|
|
90
|
+
# TODO(Michal, 09/2025): We can optimise in the future to filter annotations in a DB query.
|
|
91
|
+
objects = [
|
|
92
|
+
_annotation_to_single_obj_det(
|
|
93
|
+
annotation=annotation,
|
|
94
|
+
label_id_to_category=label_id_to_category,
|
|
95
|
+
)
|
|
96
|
+
for annotation in sample.inner.annotations
|
|
97
|
+
if annotation.annotation_type == AnnotationType.OBJECT_DETECTION
|
|
98
|
+
]
|
|
99
|
+
return ImageObjectDetection(
|
|
100
|
+
image=_sample_to_image(sample=sample, image_id=image_id),
|
|
101
|
+
objects=objects,
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _annotation_to_single_obj_det(
|
|
106
|
+
annotation: AnnotationBaseTable, label_id_to_category: dict[UUID, Category]
|
|
107
|
+
) -> SingleObjectDetection:
|
|
108
|
+
assert annotation.object_detection_details is not None
|
|
109
|
+
box = BoundingBox(
|
|
110
|
+
xmin=annotation.object_detection_details.x,
|
|
111
|
+
ymin=annotation.object_detection_details.y,
|
|
112
|
+
xmax=annotation.object_detection_details.x + annotation.object_detection_details.width,
|
|
113
|
+
ymax=annotation.object_detection_details.y + annotation.object_detection_details.height,
|
|
114
|
+
)
|
|
115
|
+
category = label_id_to_category[annotation.annotation_label.annotation_label_id]
|
|
116
|
+
return SingleObjectDetection(
|
|
117
|
+
category=category,
|
|
118
|
+
box=box,
|
|
119
|
+
confidence=annotation.confidence,
|
|
120
|
+
)
|
|
@@ -22,20 +22,16 @@ from lightly_studio.few_shot_classifier.random_forest_classifier import (
|
|
|
22
22
|
)
|
|
23
23
|
from lightly_studio.models.annotation.annotation_base import (
|
|
24
24
|
AnnotationCreate,
|
|
25
|
+
AnnotationType,
|
|
25
26
|
)
|
|
26
27
|
from lightly_studio.models.annotation_label import (
|
|
27
28
|
AnnotationLabelCreate,
|
|
28
29
|
)
|
|
29
|
-
from lightly_studio.models.annotation_task import (
|
|
30
|
-
AnnotationTaskTable,
|
|
31
|
-
AnnotationType,
|
|
32
|
-
)
|
|
33
30
|
from lightly_studio.models.classifier import EmbeddingClassifier
|
|
34
31
|
from lightly_studio.models.sample import SampleTable
|
|
35
32
|
from lightly_studio.resolvers import (
|
|
36
33
|
annotation_label_resolver,
|
|
37
34
|
annotation_resolver,
|
|
38
|
-
annotation_task_resolver,
|
|
39
35
|
embedding_model_resolver,
|
|
40
36
|
sample_embedding_resolver,
|
|
41
37
|
sample_resolver,
|
|
@@ -92,7 +88,6 @@ class ClassifierEntry:
|
|
|
92
88
|
# will be false.
|
|
93
89
|
is_active: bool = False
|
|
94
90
|
|
|
95
|
-
annotation_task_id: UUID | None = None
|
|
96
91
|
annotation_label_ids: list[UUID] | None = None
|
|
97
92
|
|
|
98
93
|
|
|
@@ -469,16 +464,14 @@ class ClassifierManager:
|
|
|
469
464
|
embeddings = [se.embedding for se in sample_embeddings]
|
|
470
465
|
predictions = classifier.few_shot_classifier.predict(embeddings)
|
|
471
466
|
if len(predictions):
|
|
472
|
-
|
|
467
|
+
_create_annotation_labels_for_classifier(
|
|
473
468
|
classifier=classifier,
|
|
474
469
|
session=session,
|
|
475
470
|
dataset_id=dataset_id,
|
|
476
471
|
)
|
|
477
472
|
else:
|
|
478
473
|
raise ValueError(f"Predict returned empty list for classifier:'{classifier_id}'")
|
|
479
|
-
# Check if annotation
|
|
480
|
-
if not classifier.annotation_task_id:
|
|
481
|
-
raise ValueError(f"Classifier with ID '{classifier_id}' has no annotation task.")
|
|
474
|
+
# Check if annotation labels are available
|
|
482
475
|
if not classifier.annotation_label_ids:
|
|
483
476
|
raise ValueError(f"Classifier with ID '{classifier_id}' has no annotation labels")
|
|
484
477
|
|
|
@@ -490,7 +483,6 @@ class ClassifierManager:
|
|
|
490
483
|
classification_annotations.append(
|
|
491
484
|
AnnotationCreate(
|
|
492
485
|
sample_id=sample_embedding.sample_id,
|
|
493
|
-
annotation_task_id=classifier.annotation_task_id,
|
|
494
486
|
dataset_id=dataset_id,
|
|
495
487
|
annotation_label_id=classifier.annotation_label_ids[max_index],
|
|
496
488
|
annotation_type=AnnotationType.CLASSIFICATION,
|
|
@@ -500,7 +492,6 @@ class ClassifierManager:
|
|
|
500
492
|
# Clear previous annotations by this classifier
|
|
501
493
|
annotation_resolver.delete_annotations(
|
|
502
494
|
session=session,
|
|
503
|
-
annotation_task_ids=[classifier.annotation_task_id],
|
|
504
495
|
annotation_label_ids=classifier.annotation_label_ids,
|
|
505
496
|
)
|
|
506
497
|
annotation_resolver.create_many(session=session, annotations=classification_annotations)
|
|
@@ -597,30 +588,18 @@ class ClassifierManager:
|
|
|
597
588
|
return self._classifiers[classifier_id]
|
|
598
589
|
|
|
599
590
|
|
|
600
|
-
def
|
|
591
|
+
def _create_annotation_labels_for_classifier(
|
|
601
592
|
session: Session,
|
|
602
593
|
dataset_id: UUID,
|
|
603
594
|
classifier: ClassifierEntry,
|
|
604
595
|
) -> None:
|
|
605
|
-
"""Create annotation
|
|
596
|
+
"""Create annotation labels for the classifier.
|
|
606
597
|
|
|
607
598
|
Args:
|
|
608
599
|
session: Database session.
|
|
609
600
|
dataset_id: The dataset ID to which the samples belong.
|
|
610
601
|
classifier: The classifier object to update.
|
|
611
602
|
"""
|
|
612
|
-
# Check if the annotation task exists and if not create it.
|
|
613
|
-
if classifier.annotation_task_id is None:
|
|
614
|
-
annotation_task = annotation_task_resolver.create(
|
|
615
|
-
session=session,
|
|
616
|
-
annotation_task=AnnotationTaskTable(
|
|
617
|
-
name=FSC_ANNOTATION_TASK_PREFIX + classifier.few_shot_classifier.name,
|
|
618
|
-
annotation_type=AnnotationType.CLASSIFICATION,
|
|
619
|
-
is_prediction=True,
|
|
620
|
-
),
|
|
621
|
-
)
|
|
622
|
-
classifier.annotation_task_id = annotation_task.annotation_task_id
|
|
623
|
-
|
|
624
603
|
# Check if the annotation label with the classifier name and class
|
|
625
604
|
# names exists and if not create it.
|
|
626
605
|
if classifier.annotation_label_ids is None:
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""Computes typicality from embeddings."""
|
|
2
|
+
|
|
3
|
+
from uuid import UUID
|
|
4
|
+
|
|
5
|
+
from lightly_mundig import Typicality # type: ignore[import-untyped]
|
|
6
|
+
from sqlmodel import Session
|
|
7
|
+
|
|
8
|
+
from lightly_studio.dataset.env import LIGHTLY_STUDIO_LICENSE_KEY
|
|
9
|
+
from lightly_studio.resolvers import (
|
|
10
|
+
metadata_resolver,
|
|
11
|
+
sample_embedding_resolver,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
DEFAULT_NUM_NEAREST_NEIGHBORS = 20
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def compute_typicality_metadata(
|
|
18
|
+
session: Session,
|
|
19
|
+
dataset_id: UUID,
|
|
20
|
+
embedding_model_id: UUID,
|
|
21
|
+
metadata_name: str = "typicality",
|
|
22
|
+
) -> None:
|
|
23
|
+
"""Computes typicality for each sample in the dataset from embeddings.
|
|
24
|
+
|
|
25
|
+
Typicality is a measure of how representative a sample is of the dataset.
|
|
26
|
+
It is calculated for each sample from its K-nearest neighbors in the
|
|
27
|
+
embedding space.
|
|
28
|
+
|
|
29
|
+
The computed typicality values are stored as metadata for each sample.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
session:
|
|
33
|
+
The database session.
|
|
34
|
+
dataset_id:
|
|
35
|
+
The ID of the dataset for which to compute the typicality.
|
|
36
|
+
embedding_model_id:
|
|
37
|
+
The ID of the embedding model to use for the computation.
|
|
38
|
+
metadata_name:
|
|
39
|
+
The name of the metadata field to store the typicality values in.
|
|
40
|
+
Defaults to "typicality".
|
|
41
|
+
"""
|
|
42
|
+
license_key = LIGHTLY_STUDIO_LICENSE_KEY
|
|
43
|
+
if license_key is None:
|
|
44
|
+
raise ValueError(
|
|
45
|
+
"LIGHTLY_STUDIO_LICENSE_KEY environment variable is not set. "
|
|
46
|
+
"Please set it to your LightlyStudio license key."
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
samples = sample_embedding_resolver.get_all_by_dataset_id(
|
|
50
|
+
session=session, dataset_id=dataset_id, embedding_model_id=embedding_model_id
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
embeddings = [sample.embedding for sample in samples]
|
|
54
|
+
typicality = Typicality(embeddings=embeddings, token=license_key)
|
|
55
|
+
typicality_values = typicality.calculate_typicality(
|
|
56
|
+
num_nearest_neighbors=DEFAULT_NUM_NEAREST_NEIGHBORS
|
|
57
|
+
)
|
|
58
|
+
assert len(samples) == len(typicality_values), (
|
|
59
|
+
"The number of samples and computed typicality values must match"
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
metadata = [
|
|
63
|
+
(sample.sample_id, {metadata_name: typicality})
|
|
64
|
+
for sample, typicality in zip(samples, typicality_values)
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
metadata_resolver.bulk_set_metadata(session, metadata)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""This module defines the base annotation model."""
|
|
2
2
|
|
|
3
3
|
from datetime import datetime, timezone
|
|
4
|
+
from enum import Enum
|
|
4
5
|
from typing import TYPE_CHECKING, List, Optional
|
|
5
6
|
from uuid import UUID, uuid4
|
|
6
7
|
|
|
@@ -22,10 +23,6 @@ from lightly_studio.models.annotation.semantic_segmentation import (
|
|
|
22
23
|
SemanticSegmentationAnnotationTable,
|
|
23
24
|
SemanticSegmentationAnnotationView,
|
|
24
25
|
)
|
|
25
|
-
from lightly_studio.models.annotation_task import (
|
|
26
|
-
AnnotationTaskTable,
|
|
27
|
-
AnnotationType,
|
|
28
|
-
)
|
|
29
26
|
|
|
30
27
|
if TYPE_CHECKING:
|
|
31
28
|
from lightly_studio.models.annotation_label import (
|
|
@@ -41,6 +38,15 @@ else:
|
|
|
41
38
|
AnnotationLabelTable = object
|
|
42
39
|
|
|
43
40
|
|
|
41
|
+
class AnnotationType(str, Enum):
|
|
42
|
+
"""The type of annotation task."""
|
|
43
|
+
|
|
44
|
+
CLASSIFICATION = "classification"
|
|
45
|
+
SEMANTIC_SEGMENTATION = "semantic_segmentation"
|
|
46
|
+
INSTANCE_SEGMENTATION = "instance_segmentation"
|
|
47
|
+
OBJECT_DETECTION = "object_detection"
|
|
48
|
+
|
|
49
|
+
|
|
44
50
|
class AnnotationBaseTable(SQLModel, table=True):
|
|
45
51
|
"""Base class for all annotation models."""
|
|
46
52
|
|
|
@@ -51,9 +57,7 @@ class AnnotationBaseTable(SQLModel, table=True):
|
|
|
51
57
|
annotation_id: UUID = Field(default_factory=uuid4, primary_key=True)
|
|
52
58
|
annotation_type: AnnotationType
|
|
53
59
|
annotation_label_id: UUID = Field(foreign_key="annotation_labels.annotation_label_id")
|
|
54
|
-
|
|
55
|
-
foreign_key="annotation_tasks.annotation_task_id",
|
|
56
|
-
)
|
|
60
|
+
|
|
57
61
|
confidence: Optional[float] = None
|
|
58
62
|
dataset_id: UUID = Field(foreign_key="datasets.dataset_id")
|
|
59
63
|
sample_id: UUID = Field(foreign_key="samples.sample_id")
|
|
@@ -61,9 +65,6 @@ class AnnotationBaseTable(SQLModel, table=True):
|
|
|
61
65
|
annotation_label: Mapped["AnnotationLabelTable"] = Relationship(
|
|
62
66
|
sa_relationship_kwargs={"lazy": "select"},
|
|
63
67
|
)
|
|
64
|
-
annotation_task: Mapped["AnnotationTaskTable"] = Relationship(
|
|
65
|
-
sa_relationship_kwargs={"lazy": "select"},
|
|
66
|
-
)
|
|
67
68
|
sample: Mapped[Optional["SampleTable"]] = Relationship(
|
|
68
69
|
sa_relationship_kwargs={"lazy": "select"},
|
|
69
70
|
)
|
|
@@ -101,7 +102,6 @@ class AnnotationCreate(SQLModel):
|
|
|
101
102
|
""" Required properties for all annotations. """
|
|
102
103
|
annotation_label_id: UUID
|
|
103
104
|
annotation_type: AnnotationType
|
|
104
|
-
annotation_task_id: UUID
|
|
105
105
|
confidence: Optional[float] = None
|
|
106
106
|
dataset_id: UUID
|
|
107
107
|
sample_id: UUID
|
|
@@ -140,7 +140,6 @@ class AnnotationView(SQLModel):
|
|
|
140
140
|
annotation_id: UUID
|
|
141
141
|
annotation_type: AnnotationType
|
|
142
142
|
annotation_label: AnnotationLabel
|
|
143
|
-
annotation_task_id: UUID
|
|
144
143
|
confidence: Optional[float] = None
|
|
145
144
|
|
|
146
145
|
object_detection_details: Optional[ObjectDetectionAnnotationView] = None
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from .create import create
|
|
4
4
|
from .delete import delete
|
|
5
|
-
from .get_all import get_all
|
|
5
|
+
from .get_all import get_all, get_all_sorted_alphabetically
|
|
6
6
|
from .get_by_id import get_by_id
|
|
7
7
|
from .get_by_ids import get_by_ids
|
|
8
8
|
from .get_by_label_name import get_by_label_name
|
|
@@ -13,6 +13,7 @@ __all__ = [
|
|
|
13
13
|
"create",
|
|
14
14
|
"delete",
|
|
15
15
|
"get_all",
|
|
16
|
+
"get_all_sorted_alphabetically",
|
|
16
17
|
"get_by_id",
|
|
17
18
|
"get_by_ids",
|
|
18
19
|
"get_by_label_name",
|
|
@@ -20,3 +20,18 @@ def get_all(session: Session) -> list[AnnotationLabelTable]:
|
|
|
20
20
|
select(AnnotationLabelTable).order_by(col(AnnotationLabelTable.created_at).asc())
|
|
21
21
|
).all()
|
|
22
22
|
return list(labels) if labels else []
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def get_all_sorted_alphabetically(session: Session) -> list[AnnotationLabelTable]:
|
|
26
|
+
"""Retrieve all annotation labels sorted alphabetically.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
session (Session): The database session.
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
list[AnnotationLabelTable]: A list of annotation labels.
|
|
33
|
+
"""
|
|
34
|
+
labels = session.exec(
|
|
35
|
+
select(AnnotationLabelTable).order_by(col(AnnotationLabelTable.annotation_label_name).asc())
|
|
36
|
+
).all()
|
|
37
|
+
return list(labels) if labels else []
|