Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history


merge
  • Loading branch information
mikusg committed Mar 4, 2024
2 parents bb38eb5 + 8716df1 commit 94def0d
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 23 deletions.
114 changes: 91 additions & 23 deletions server/routes/api/class-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,27 @@ const getPublicNamespaces = async () => {
}
// **************************************************************************************************************
const xx_getClassListExt = async (schema, params) => {
function roundCount(cnt) {
if ( cnt == '' || cnt == 0) {
return '';
}
else {
cnt = Number(cnt);
if ( cnt < 10000)
return cnt;
else
return cnt.toPrecision(2).replace("+", "");
}
}

let r;
let rr;
let ca = '';
if ( params.main.has_classification_adornment ) ca = ', classification_adornment';
let sql = `select id, display_name, prefix, is_local, cnt, cnt_x ${ca} from ${schema}.v_classes_ns_main order by is_local desc, prefix, cnt desc LIMIT $1`;
rr = await util.getSchemaData(sql, params);
rr = addFullNames(rr, params);
sql = `select * from ${schema}.cc_rels`;
sql = `select * from ${schema}.cc_rels where type_id = 1 or type_id = 2`;
r = await util.getSchemaData(sql, params, false);
const cc_rels = r.data;

Expand All @@ -250,13 +263,19 @@ const xx_getClassListExt = async (schema, params) => {
else
c.is_local = 0;

// Paņemu drusku vājākus kaimiņus, kuri varētu arī kaimiņi nesanākt (vairs nepaņemu)

// sql = `select distinct(class_id) from ${schema}.cp_rels where type_id = 2 and class_id <> ${c.id} and property_id in
//( select property_id from ${schema}.cp_rels where class_id = ${c.id} and type_id = 1 )`;
sql = `select distinct(class_id) from ${schema}.cp_rels where type_id = 2 and cover_set_index > 0 and class_id <> ${c.id} and property_id in
( select property_id from ${schema}.cp_rels where class_id = ${c.id} and type_id = 1 and cover_set_index > 0)`;
//*** Kaimiņus vispār vairs neņemam
//***sql = `select distinct(class_id) from ${schema}.cp_rels where type_id = 2 and cover_set_index > 0 and class_id <> ${c.id} and property_id in
//*** ( select property_id from ${schema}.cp_rels where class_id = ${c.id} and type_id = 1 and cover_set_index > 0)`;
//***r = await util.getSchemaData(sql, params, false);
//***c.c = r.data.map( v => { return v.class_id});
sql = `select sum(object_cnt) from ${schema}.cp_rels where type_id = 1 and class_id = ${c.id}`;
r = await util.getSchemaData(sql, params, false);
c.c = r.data.map( v => { return v.class_id});
const in_props = (r.data[0].sum == null) ? '' : ` in_props-${roundCount(Number(r.data[0].sum))}`;
c.in_props = (r.data[0].sum == null) ? 0 : Number(r.data[0].sum);
c.cnt_sum = c.cnt + Math.round(Math.pow(c.in_props, 5/6));

c.s = [c.id];
if ( cc_rels.length > 0 ) {
Expand All @@ -267,25 +286,28 @@ const xx_getClassListExt = async (schema, params) => {
c.s = [...new Set([...c.s, ...cc_rels.filter(function(s){ return c.s.includes(s.class_1_id)}).map( v => { return v.class_2_id})])];
}
}
c.display_name = `${c.full_name} (weight-${roundCount(c.cnt_sum)} cnt-${roundCount(c.cnt)} ${in_props})`;
c.sel = 0;
ii = ii + 1;
}

for (var c of rr.data) {
for (var cc of c.c) {
let cx = rr.data.filter(function(n){ return n.id == cc});
if ( !cx[0].c.includes(c.id) )
cx[0].c.push(c.id);
}
}
//***for (var c of rr.data) {
//*** for (var cc of c.c) {
//*** let cx = rr.data.filter(function(n){ return n.id == cc});
//*** if ( !cx[0].c.includes(c.id) )
//*** cx[0].c.push(c.id);
//*** }
//***}

for (var c of rr.data) {
c.display_name = `${c.full_name} ( cnt-${c.cnt_x} N-${c.c.length} )`;
c.selected = 0;
}
//***for (var c of rr.data) {
//*** //***c.display_name = `${c.full_name} ( cnt-${c.cnt_x} N-${c.c.length} )`;
//*** c.display_name = `${c.full_name} ( cnt-${c.cnt_x} )`;
//*** c.selected = 0;
//***}

//concat(prefix,':',display_name, ' (', cnt_x, ')' )
rr.data = rr.data.sort(function(a,b){ return b.cnt-a.cnt;})
rr.data = rr.data.sort(function(a,b){ return b.cnt_sum-a.cnt_sum;});

return rr;
}
const xx_getPropList = async (schema, params) => {
Expand Down Expand Up @@ -323,8 +345,42 @@ const xx_getPropList = async (schema, params) => {

return r;
}
const xx_getPropList2 = async (schema, params) => {
// TODO pagaidām ir noņemta ns filtra iespēja, remSmall arī vairs nebūs
function roundCount(cnt) {
if ( cnt == '' || cnt == 0) {
return '';
}
else {
cnt = Number(cnt);
if ( cnt < 10000)
return cnt;
else
return cnt.toPrecision(2).replace("+", "");
}
}

const sql = `select id, display_name, prefix, cnt, object_cnt, data_cnt, max_cardinality, inverse_max_cardinality, domain_class_id, range_class_id,
(select count(*) from ${schema}.cp_rels where property_id = vpn.id and cover_set_index > 0 and type_id = 2) as type_2,
(select count(*) from ${schema}.cp_rels where property_id = vpn.id and cover_set_index > 0 and type_id = 1) as type_1
from ${schema}.v_properties_ns vpn where id in (select distinct(property_id) from ${schema}.cp_rels where class_id in (${params.main.c_list})) order by cnt desc`;

let r = await util.getSchemaData(sql, params);

for (var c of r.data) {
if ( c.cnt == c.object_cnt )
c.p_name = `${c.prefix}:${c.display_name} (cnt-${roundCount(c.cnt)}, object property ${c.type_2}-${c.type_1})`;
else if ( c.cnt == c.data_cnt )
c.p_name = `${c.prefix}:${c.display_name} (cnt-${roundCount(c.cnt)}, data property )`;
else
c.p_name = `${c.prefix}:${c.display_name} (cnt-${roundCount(c.cnt)}, property ${c.type_2}-${c.type_1})`;

}

return r;
}
const xx_getClassListInfo = async (schema, params) => {
let sql = `select * from ${schema}.cc_rels where class_1_id in (${params.main.c_list}) and class_2_id in (${params.main.c_list})`;
let sql = `select * from ${schema}.cc_rels where class_1_id in (${params.main.c_list}) and class_2_id in (${params.main.c_list}) and ( type_id = 1 or type_id = 2 )`;
let rr = await util.getSchemaData(sql, params, false);
const cc_rels = rr.data;
let cp = '';
Expand All @@ -335,7 +391,7 @@ const xx_getClassListInfo = async (schema, params) => {
if ( params.main.has_classification_adornment )
cp = `${cp} classification_adornment,`;

sql = `select id, prefix, display_name, cnt_x, cnt, ${cp}
sql = `select id, prefix, display_name, cnt_x, cnt, ${cp} is_local,
(select count(*) from ${schema}.cp_rels cr where class_id = vcnm.id and type_id = 2 and data_cnt > 0) as data_prop,
(select count(*) from ${schema}.cp_rels cr where class_id = vcnm.id and type_id = 2 and object_cnt > 0) as obj_prop
from ${schema}.v_classes_ns_main vcnm where id in (${params.main.c_list})`;
Expand All @@ -346,32 +402,43 @@ const xx_getClassListInfo = async (schema, params) => {
for (var c of rr.data) {
c.s = [c.id];
c.b = [c.id];
c.s0 = [];
c.b0 = [];

sql = `select sum(object_cnt) from ${schema}.cp_rels where type_id = 1 and class_id = ${c.id}`;
r = await util.getSchemaData(sql, params, false);
c.in_props = (r.data[0].sum == null) ? 0 : Number(r.data[0].sum);
c.cnt_sum = c.cnt + Math.round(Math.pow(c.in_props, 5/6));

if ( cc_rels.length > 0 ) {
let len = 1;
c.s = [...new Set([...c.s, ...cc_rels.filter(function(s){ return c.s.includes(s.class_1_id)}).map( v => { return v.class_2_id})])];
c.s0 = cc_rels.filter(function(s){ return s.class_1_id == c.id; }).map( v => { return v.class_2_id});
while ( len < c.s.length) {
len = c.s.length;
c.s = [...new Set([...c.s, ...cc_rels.filter(function(s){ return c.s.includes(s.class_1_id)}).map( v => { return v.class_2_id})])];
}
c.b = [...new Set([...c.b, ...cc_rels.filter(function(s){ return c.b.includes(s.class_2_id)}).map( v => { return v.class_1_id})])];
c.b0 = cc_rels.filter(function(s){ return s.class_2_id == c.id; }).map( v => { return v.class_1_id});
while ( len < c.b.length) {
len = c.b.length;
c.b = [...new Set([...c.b, ...cc_rels.filter(function(s){ return c.b.includes(s.class_2_id)}).map( v => { return v.class_1_id})])];
}
}
}

return rr;
return rr;
}
const xx_getCCInfo = async (schema, params) => {

const sql = `select class_1_id, class_2_id from ${schema}.cc_rels where class_1_id in (${params.main.c_list}) and class_2_id in (${params.main.c_list})`;
const sql = `select class_1_id, class_2_id from ${schema}.cc_rels where ( type_id = 1 or type_id = 2 ) and class_1_id in (${params.main.c_list}) and class_2_id in (${params.main.c_list})`;
const r = await util.getSchemaData(sql, params);

return r;
}
const xx_getCPCInfo = async (schema, params) => {
const sql = `select * from ${schema}.cpc_rels`;
//const sql = `select * from ${schema}.cpc_rels`;
const sql = `select cpc.*, class_id, property_id, type_id from ${schema}.cpc_rels cpc, ${schema}.cp_rels cp where cpc.cp_rel_id = cp.id and cp.cover_set_index > 0`;
const r = await util.getSchemaData(sql, params);
return r;
}
Expand Down Expand Up @@ -422,6 +489,7 @@ module.exports = {
getTreeClasses,
xx_getClassListExt,
xx_getPropList,
xx_getPropList2,
xx_getClassListInfo,
xx_getCCInfo,
xx_getCPCInfo,
Expand Down
4 changes: 4 additions & 0 deletions server/routes/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const {
xx_getClassList,
xx_getClassListExt,
xx_getPropList,
xx_getPropList2,
xx_getClassListInfo,
xx_getClassInfo,
xx_getClassInfoAtr,
Expand Down Expand Up @@ -308,6 +309,9 @@ router.post('/ontologies/:ont/:fn', wrapAsync(async (req, res, next) => {
if ( fn === 'xx_getPropList') {
r = await xx_getPropList(schema, params);
}
if ( fn === 'xx_getPropList2') {
r = await xx_getPropList2(schema, params);
}
if ( fn === 'xx_getClassListInfo') {
r = await xx_getClassListInfo(schema, params);
}
Expand Down

0 comments on commit 94def0d

Please sign in to comment.