{"id":16,"date":"2021-03-04T12:07:35","date_gmt":"2021-03-04T12:07:35","guid":{"rendered":"http:\/\/imdeafoodcompubio.com\/?page_id=16"},"modified":"2023-01-31T08:46:46","modified_gmt":"2023-01-31T08:46:46","slug":"text-mining","status":"publish","type":"page","link":"https:\/\/imdeafoodcompubio.com\/index.php\/text-mining\/","title":{"rendered":"Text-Mining"},"content":{"rendered":"<!DOCTYPE html>\r\n<html lang=\"en\">\r\n<head>\r\n<meta charset=\"UTF-8\">\r\n<title><\/title>\r\n  <link rel=\"stylesheet\" href=\"\/\/code.jquery.com\/ui\/1.13.2\/themes\/base\/jquery-ui.css\">\r\n<script src=\"https:\/\/code.jquery.com\/jquery-3.6.0.min.js\"><\/script>\r\n<script src=\"https:\/\/code.jquery.com\/jquery-migrate-1.4.1.min.js\"><\/script>\r\n  <script src=\"https:\/\/code.jquery.com\/ui\/1.13.2\/jquery-ui.js\"><\/script>\r\n\r\n\r\n\r\n<link rel=\"stylesheet\" href=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@4.5.3\/dist\/css\/bootstrap.min.css\" integrity=\"sha384-TX8t27EcRE3e\/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2\" crossorigin=\"anonymous\">\r\n<script src=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@4.5.3\/dist\/js\/bootstrap.bundle.min.js\" integrity=\"sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ\/JpcUGGOn+Y7RsweNrtN\/tE3MoK7ZeZDyx\" crossorigin=\"anonymous\"><\/script>\r\n\r\n<link rel=\"stylesheet\" type=\"text\/css\" href=\"https:\/\/cdn.datatables.net\/v\/dt\/dt-1.13.1\/datatables.min.css\"\/>\r\n \r\n<script type=\"text\/javascript\" src=\"https:\/\/cdn.datatables.net\/v\/dt\/dt-1.13.1\/datatables.min.js\"><\/script>\r\n\r\n\r\n<script type=\"text\/javascript\" src=\"https:\/\/unpkg.com\/vis-network\/standalone\/umd\/vis-network.min.js\"><\/script>\r\n\r\n<style>\r\n    body{\r\n        font-family: Arial, sans-serif;\r\n                \r\n\r\n    }\r\n    #divtable{\r\n      font-size:20px;  \r\n    }\r\n#numerosearch{\r\n    max-width: 200px;\r\n    float:right;\r\n    height: 40px;\r\n        padding: 5px 10px;\r\n        border: 1px solid #CCCCCC;\r\n        font-size: 22px;\r\n        max-height: 100px;\r\n}\r\n\r\n.search-box{\r\n    margin:5%;\r\n    margin-left:10%;\r\n    width: 80%;\r\n    \r\n        position: relative;\r\n        display:inline-block;\r\n        font-size: 22px;\r\n        padding-bottom: 0px;\r\n    }\r\n    \r\n   .column{\r\n                background-color:white;\r\n            width: 100%;\r\n            border-radius: 10px;\r\n              \/*box-shadow: 5px 10px #f1f1f1;*\/\r\n        \r\n }  \r\n    .search-box input[type=\"text\"]{\r\n        height: 60px;\r\n        padding: 5px 10px;\r\n        border: 1px solid #CCCCCC;\r\n        font-size: 22px;\r\n        max-height: 100px;\r\n    }\r\n       .search-box input[type=\"number\"]{\r\n        height: 60px;\r\n        padding: 5px 10px;\r\n        border: 1px solid #CCCCCC;\r\n        font-size: 22px;\r\n        max-height: 100px;\r\n    }\r\n    .result{\r\n        z-index: 999;\r\n        top: 100%;\r\n        left: 0;\r\n        overflow: auto;\r\n        opacity: 1;\r\n    }\r\n    .search-box input[type=\"text\"], .result{\r\n        width: 100%;\r\n        box-sizing: border-box;\r\n        max-height: 115px;\r\n        opacity: 1;\r\n    }\r\n    .result p{\r\n        margin: 0;\r\n        padding: 7px 10px;\r\n        border: 1px solid #CCCCCC;\r\n        border-top: none;\r\n        cursor: pointer;\r\n        max-height: 100px;\r\n    }\r\n    .result p:hover{\r\n        background: #f2f2f2;\r\n        max-height: 100px;\r\n    }\r\n\r\n        .peque{\r\n            width: 100px;\r\n        }\r\n        .button{         \r\n            float:right; \r\n  background-color: #4CAF50; \r\n  border: none;\r\n  color: white;\r\n  height: 10%;\r\n  text-align: center;\r\n  text-decoration: none;\r\n  font-size: 10px;\r\n        }\r\n\r\n\r\ninput[type=\"radio\"]{\r\n    height: 20px;\r\n  width: 15px;\r\n}\r\n.site-content{\r\n    height: auto;\r\n}\r\n\r\n#mynetwork{\r\nheight:500px;\r\nwidth:auto;   \r\nbackground-color:white;\r\n            border-radius: 10px;\r\n\r\nmargin-top:2%;\r\n\r\n}\r\n #divtable{\r\n    background-color:white; \r\n                border-radius: 10px;\r\n\r\nwidth:auto;   \r\nmargin-top:2%;\r\n }\r\n\r\n\r\n.cardt{\r\n    width:85%;\r\n    margin-left:7.5%;\r\n    margin-bottom:7.5%;\r\n}\r\n.card-content {\r\n    flex: 1 1 auto;\r\n}\r\ndt{\r\n        font-size:22px;\r\n\r\n}\r\ndd {\r\n        font-size:22px;\r\n}\r\ndl {\r\n    display: flex;\r\n    flex-wrap: wrap;\r\n    margin-right: -15px;\r\n    margin-left: -15px;\r\n    background: #fff;\r\n    padding: 0.7rem 1.5rem;\r\n    margin: 0;\r\n    position: relative;\r\n\r\n}\r\n.card-content dl dd, .card-content dl dt {\r\n    border-bottom: 1px dotted #aab3c1;\r\n    padding: 0.8rem 0;\r\n    margin: 0;\r\n}\r\n.card-content dl dd:last-of-type ,   .card-content dl dt:last-of-type {\r\n    border:none;\r\n}\r\n    .card-content h1 {\r\n          text-align:center;\r\n                   \r\n\r\n    }\r\n    .titlestudy{\r\nborder-top:    1px solid black;\r\nborder-bottom: 1px solid black;\r\n\r\n\r\n                    margin:auto;\r\n    }\r\n@media (max-width: 575.98px) { \r\n    .card-content dl dt {\r\n    border-bottom: none;\r\n}\r\n\r\n}\r\n\r\n.form-control:focus {\r\n  border-color: #0000FF;\r\n  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102,205,170, 0.6);\r\n}\r\ndiv.dataTables_wrapper {\r\n    width: 80%;\r\n    margin: 2%;\r\n    margin-left: 10%;\r\n    margin-right: 10%;\r\n    font-size:22px;\r\n    \r\n}\r\n.carousel-item.active,\r\n.carousel-control-next,\r\n.carousel-control-prev{\r\n    display:flex;\r\n}\r\n\r\n.carousel-control-next,\r\n.carousel-control-prev , \r\n.carousel-indicators  {\r\n    filter: invert(100%);\r\n}\r\n#myCarousel{\r\n    margin-top:2%;\r\n\r\n}\r\n        .helpresult{\r\n        z-index: 999;\r\n        top: 100%;\r\n        left: 10%;\r\n        overflow: auto;\r\n        opacity: 1;\r\n    }\r\n           #divtable p{\r\n     color: black !important ;\r\n    }\r\n        .helpresult p , .helpresult h2{\r\n            font-size:0.9vw;\r\n        margin: 0;\r\n        margin-left:2%;\r\n        font-style:italic;\r\n        max-height: 100px;\r\n    }\r\n        .dataTables_length, .dataTables_length select\r\n    { \r\n        font-size: 1.5em;\r\n        \r\n    }\r\n    .popover{\r\n                font-size: 2em;\r\n\r\n    }\r\n    #divtable h2 , #divtable2 h2{\r\n    display:inline; \r\n }\r\n    caption {\r\n        text-align:center;\r\n                font-style:italic;\r\n                caption-side:top;\r\n    }\r\n    .btn-primary {\r\n        width:10%;\r\n        font-size:16px;\r\n        margin-left:50%;\r\n        }\r\n    \r\n#modaldesc {\r\n  position: absolute;\r\n  left: 50%;\r\n  top: 50%;\r\n  transform: translate(-50%, -50%);\r\n}\r\n.btn-secondary{\r\n            width:20%;\r\n        font-size:16px;\r\n        margin-left:10%;\r\n}\r\n.modal-body {\r\n    display:inline;\r\n}\r\n<\/style>\r\n<\/head>\r\n<body>\r\n<div class=\"column\">\r\n    <div class=\"search-box\">\r\n           Food, food compound or drug <img id=\"datahelp1\" class=\"help \"src=\"http:\/\/imdeafoodcompubio.com\/wp-content\/uploads\/2022\/06\/icon1.png\"   width=\"15\" \/> \r\n          <div class=\"helpresult\" id=\"help1\"><\/div>\r\n           <input type=\"text\" id=\"key\" class=\"key form-control\" placeholder='Grapefruit'>\r\n            <div class=\"result\" id=\"result\"><\/div>\r\n            <div id=\"networkdiv\">\r\n             Number of Nodes  <img id=\"datahelpnodes\" class=\"help \"src=\"http:\/\/imdeafoodcompubio.com\/wp-content\/uploads\/2022\/06\/icon1.png\"   width=\"15\" \/> \r\n          <div class=\"helpresult\" id=\"helpnodes\"><\/div>\r\n            <input type=\"number\" id=\"edges\" name=\"edges\" class=\"form-control\"  value=10 min=\"1\">\r\n            <\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n<div id='divtable'>\r\n    \r\n<table id=\"table\" class=\"hover\" style=\"width:100%\">\r\n    <caption> Click in the row of interest to get more information <\/caption>\r\n<\/table>\r\n<\/div>\r\n\r\n<div id=\"mynetwork\"><\/div>\r\n\r\n\r\n<div id=\"myCarousel\" class=\"carousel slide card\"  data-interval=\"false\" data-ride=\"carousel\">\r\n    \r\n    \r\n<button type=\"button\" class=\"btn btn-primary\" data-toggle=\"modal\" data-target=\"#modaldesc\">\r\nDownload\r\n<\/button>\r\n\r\n<div class=\"modal fade\" id=\"modaldesc\"  role=\"dialog\">\r\n  <div class=\"modal-dialog\">\r\n    <div class=\"modal-content\">\r\n      <div class=\"modal-header\">\r\n        <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-label=\"Close\">\r\n          <span aria-hidden=\"true\">&times;<\/span>\r\n        <\/button>\r\n      <\/div>\r\n      <div class=\"modal-body\">\r\n        <button type=\"button\" id='copy' class=\"btn btn-secondary\">copy\r\n         <img id=\"datahelpcopy\" class=\"help \"src=\"http:\/\/imdeafoodcompubio.com\/wp-content\/uploads\/2022\/06\/icon1.png\"   width=\"15\" \/> \r\n         <\/button>\r\n        <button type=\"button\" id='tsv' class=\"btn btn-secondary\">TSV<\/button>\r\n        <button type=\"button\" id='csv' class=\"btn btn-secondary\">CSV<\/button>\r\n        \r\n                  <div class=\"helpresult\" id=\"helpcopy\"><\/div>\r\n\r\n      <\/div>\r\n    <\/div>\r\n  <\/div>\r\n<\/div>\r\n\r\n  <ol class=\"carousel-indicators\">\r\n  <\/ol>\r\n\r\n\r\n  <div class=\"carousel-inner\">\r\n  <\/div>\r\n\r\n  <a class=\"carousel-control-prev\" href=\"#myCarousel\" role=\"button\" data-slide=\"prev\">\r\n    <span class=\"carousel-control-prev-icon\" aria-hidden=\"true\"><\/span>\r\n    <span class=\"sr-only\">Previous<\/span>\r\n  <\/a>\r\n  <a class=\"carousel-control-next\" href=\"#myCarousel\" role=\"button\" data-slide=\"next\">\r\n    <span class=\"carousel-control-next-icon\" aria-hidden=\"true\"><\/span>\r\n    <span class=\"sr-only\">Next<\/span>\r\n  <\/a>\r\n\r\n<\/div>\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n<script>\r\njQuery(document).ready(function($) {\r\n    \r\n    $(\"#image-id\").click(function(){\r\n        $(\"#modal-id\").modal();\r\n    });\r\n\/\/ Define variables and set hide values \u200b\u200bfor css\r\nvar datacharge = true;\r\n$(\".card\").hide();\r\n$(\"#myCarousel\").hide();\r\n    $(\"#mynetwork\").hide();\r\n        $(\"#networkdiv\").hide();\r\n\r\n           $(\"#divtable\").hide();\r\n\r\n    $(\"#htbotones\").hide();\r\n    $(\"#data\").hide();\r\n    var table;\r\n    var tableid;\r\n    var key =\"\";\r\n    var idmax;\r\n    var datos=[];\r\n    var comprobar=[];\r\n    var datosarray =[];\r\n    var type;\r\n    var keydata;\r\n    var datanew ={};\r\n    var pagesession=0;\r\n    var arraynom = [\"num\"  ,\"food\",\"drug\"];\r\n\r\n\r\n   $(document).on('click', '.help', function() { \r\n        var idhelp = $(this).attr(\"id\");\r\nif (idhelp==\"datahelp1\") {\r\n    window.open('http:\/\/imdeafoodcompubio.com\/index.php\/help\/#text', '_blank');\r\n}\r\n\r\n    });\r\n\r\n$(document).on(\"mouseenter\", \".help\", function(){\r\n$(\".helpresult\").empty();\r\nvar idhelp = $(this).attr(\"id\");\r\nif (idhelp==\"datahelp1\") {\r\n            $(\"#help1\").append(\"<p>Type the term of interest. If FooDrugs database doesn't have experiments with the query term a \u201cNo Results Found\u201d message will appear.<\/p>\");\r\n                    \r\n}   \r\nelse if (idhelp==\"datahelpentries\") {\r\n            $(\"#helpentries\").append(\"<p>Allow you to filter the number of studies to display<\/p>\");\r\n                    \r\n}   \r\nelse if (idhelp==\"datahelpfilter\") {\r\n            $(\"#helpfilter\").append(\"<p>Allow you to filter with free text on the table by any field<\/p>\");\r\n                    \r\n}else if (idhelp==\"datahelpnodes\") {\r\n            $(\"#helpnodes\").append(\"<p>Allow you to select the number of nodes displayed in the network ,  beyond the table can find the network<\/p>\");\r\n                    \r\n}  else if (idhelp==\"datahelpcopy\"){\r\n                $(\"#helpcopy\").append(\"<p>Allow to copy the information on the clipboard<\/p>\");\r\n\r\n}\r\n\r\n});\r\n\r\n$(document).on(\"mouseleave\", \".help\", function(){\r\n$(\".helpresult\").empty();\r\n    });\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n        \/\/Keyup event to fill the div which will show the autocomplete suggestions\r\n    $('.key').on('keyup input', function() {    \r\n                        \/\/We get the value and the id of the input.    \r\n    var key = $(this).val();\r\n    \/\/We check that the value is not null or empty\r\nif(key != \"\"){\r\n    jQuery.ajax({\r\n            \/\/We make a request to ajax that redirects us to another script where the Mysql query will be executed and will return the first 5 records similar to what is being searched for\r\n        url:'https:\/\/imdeafoodcompubio.com\/wp-content\/themes\/bento-child\/textmining\/ajaxsql.php',\r\n        type: 'post',\r\n        data: {search:key, type:1},\r\n        dataType: 'json',\r\n        success:function(response){\r\n            \r\n                         \/\/We get the length of the response and add one by one the response in the div\r\n                var len = response.length;\r\n                $(\"#result\").empty();\r\n                var repetidos = [];\r\n                for( var i = 0; i<len; i++){\r\n                    var name = response[i]['name'];\r\n                    if(repetidos.includes(name) == false ){\r\n                        $(\"#result\").append(\"<p>\"+name+\"<\/p>\");\r\n                        repetidos.push(name);\r\n                    }\r\n                }   \r\n        }, error: function(XMLHttpRequest, textStatus, errorThrown) { \r\n        alert(\"Status: \" + textStatus); alert(\"Error: \" + errorThrown); \r\n    }  \r\n    });\r\n        \/\/If the answer is empty, the result is cleaned\r\n}else {\r\n    $(\".result\").empty();\r\n}\r\n})\r\n\/\/CLICK event on any results\r\n$(document).on(\"click\", \".result p\", function(){\r\n    \/\/reset values , get the value of the key and call the function\r\n        $('#result').empty();     \r\n         $('#key').val($(this).text());\r\n         mostrartablas();\r\n        });\r\n\r\n\r\n\/\/Function mostrartablas \r\nfunction mostrartablas(){\r\n    \/\/get the value of the key\r\n     key = $('#key').val();\r\n     keydata=key;\r\n     comprobar=[];\r\n    $.ajax({\r\n    url:'https:\/\/imdeafoodcompubio.com\/wp-content\/themes\/bento-child\/textmining\/ajaxsql.php',\r\n    type: 'post',\r\n    data: {search:key, type:2},\r\n    dataType: 'json',\r\n    success:function(response){\r\n        \/\/save the value from the response\r\n        datos['a']=response;\r\ndatos['b'] = Array.from(response);\r\n        dataparser=response;\r\n        datosc=response;\r\n        \r\n\/\/ Parse the array checking that there are no duplicates or empty values\r\nlistfood=[];\r\nlistdrug=[];\r\nlistcont=[];\r\ndatafooddrug=[];\r\nfor (let j = 0; j < datosc.length; j++) {\r\n    var provisional = datosc[j];\r\n    console.log(provisional['food'].toLowerCase().localeCompare(key.toLowerCase())==0);\r\n    if (provisional['food'].toLowerCase().localeCompare(key.toLowerCase())==0) {\r\n        if (!listdrug.includes(provisional['drug'].toLowerCase())) {\r\n            listdrug.push(provisional['drug'].toLowerCase());\r\n            provt = [];\r\n            provt['food']=key;\r\n            provt['drug'] = (provisional['drug']);\r\n            \r\n            provt['total']=1;\r\n                        provt['link']= linktype(provisional['link']);\r\n            datafooddrug[datafooddrug.length] = provt;\r\n            console.log(provt);\r\n        }else {\r\n                for (let index = 0; index < datafooddrug.length; index++) {\r\n                    if (datafooddrug[index]['drug'].toLowerCase()==provisional['drug'].toLowerCase()){\r\n                           datafooddrug[index]['total']=datafooddrug[index]['total']+1;\r\n                           var lkpar = linktype(provisional['link']);\r\n                        if (lkpar!=datafooddrug[index]['link']){\r\n                                                        var pos = datafooddrug[index]['link'].search('\/');\r\n                            if(pos==-1){\r\n                                datafooddrug[index]['link']=datafooddrug[index]['link']+'\/'+lkpar;\r\n                            }else {\r\n\r\n                            }\r\n                    }\r\n}\r\n        }\r\n        }\r\n    \r\n    }else if (provisional['drug'].toLowerCase().localeCompare(key.toLowerCase())==0) {\r\n        if (!listfood.includes(provisional['food'].toLowerCase())) {\r\n            listfood.push(provisional['food'].toLowerCase());\r\n            provt = [];\r\n            provt['food'] = (provisional['food']);\r\n            provt['drug']=key;\r\n            \r\n            provt['total']=1;\r\n            provt['link']=linktype(provisional['link']);\r\n            datafooddrug[datafooddrug.length] = provt;\r\n            listcont[provisional['food'].toLowerCase]=datafooddrug.length;\r\n            console.log(provt);\r\n        }else {\r\n        for (let index = 0; index < datafooddrug.length; index++) {\r\n                    if (datafooddrug[index]['food'].toLowerCase()==provisional['food'].toLowerCase()){\r\n                           datafooddrug[index]['total']=datafooddrug[index]['total']+1;\r\n                        \/\/datafooddrug[index]['links'].push(provisional['link']);\r\n                    }\r\n    \r\n}\r\n        }\r\n    }\r\n}\r\n\r\n\r\n  \/*      for (let k = 0; k < dataparser.length; k++) {\r\n            var provisional = dataparser[k];\r\n            if (comprobar.includes(provisional['drug'])==false && comprobar.includes(provisional['food'])==false  ) {\r\n            if (provisional['food'].toLowerCase().localeCompare(key.toLowerCase())==0) {\r\n                comprobar.push(provisional['drug']);\r\n            }else if(provisional['drug'].toLowerCase().localeCompare(key.toLowerCase())==0) {\r\n                comprobar.push(provisional['food']);\r\n            } \r\n                }else {\r\n                    k=k-1;\r\n                            dataparser.splice(k,1);\r\n                }\r\n        }*\/\r\n        \r\n        \r\n        \r\n               datanew=[];\r\n               \r\n        for (let index = 0; index < datafooddrug.length; index++) {\r\n    datanew[index]=[];\r\n        \r\n\r\nfor (var value in datafooddrug[index]){\r\n    datanew[index].push(datafooddrug[index][value]);\r\n}\r\n}\r\nif(datacharge==true){\r\n    datacharge=false;\r\n}else {\r\n    table.destroy();\r\n}\r\n        table = $('#table').DataTable({\r\n        data: datanew,\r\n        dom: 'lrftip',\r\n  language: {\r\n        \"lengthMenu\": '<h2> Show entries <\/h2> <img decoding=\"async\" class=\"help\" id=\"datahelpentries\" src=\"http:\/\/imdeafoodcompubio.com\/wp-content\/uploads\/2022\/06\/icon1.png\" width=\"15\"><\/img>   <div class=\"helpresult\" id=\"helpentries\"><\/div> _MENU_' ,\r\n    \"search\": ' <h2> Filter Records<\/h2> <img decoding=\"async\" class=\"help\" id=\"datahelpfilter\" src=\"http:\/\/imdeafoodcompubio.com\/wp-content\/uploads\/2022\/06\/icon1.png\" width=\"15\"><\/img>  <div class=\"helpresult\" id=\"helpfilter\"><\/div> _INPUT_' \r\n    },\r\n    \r\n        columns: [\r\n            { title: \"Food\" },\r\n            { title: \"Drug\"},\r\n            { title: \"<span  id='tablepopover' tabindex='0' data-toggle='popover' data-content='The same interaction can appear multiple times in the text'> Number Total of Citation <img  src='http:\/\/imdeafoodcompubio.com\/wp-content\/uploads\/2022\/06\/icon1.png'   width='15' \/> <\/span>\" \r\n            },\r\n            { title: \"Sources\" },\r\n        ],\r\n    });\r\n    \r\n    \r\n    \r\n       \/\/ $('div.toolbar').html('<b> Click in the row of interest to get more information  <\/b>');\r\n              $('[data-toggle=\"popover\"]').popover({\r\n    'trigger': 'hover',\r\n});\r\n       $(\"#divtable\").show();\r\n\r\n       $(\"#mynetwork\").show();\r\n              $(\"#networkdiv\").show();\r\n       nodo();\r\n    } ,error: function(XMLHttpRequest, textStatus, errorThrown) { \r\n        alert(\"Status: \" + textStatus); alert(\"Error: \" + errorThrown); \r\n    }  \r\n    });\r\n}\r\n\r\n\r\n\r\nfunction linktype (lk){\r\nvar x = lk.substr(8,1);\r\nvar lkparse='';\r\nif (x=='p'){\r\n    lkparse='Pubmed';\r\n\r\n}else if (x=='g') {\r\n        lkparse='DrugBank';\r\n\r\n}else if (x=='w') {\r\n        lkparse='Drugs.com';\r\n\r\n}else if (x=='c')  {\r\n        lkparse='clinicaltrials';\r\n\r\n}\r\n    return lkparse;\r\n}\r\n\r\n\r\n\r\n\/\/table click event \r\n      $(document).on('click', '#table tr', function() { \r\n            \/\/Change the color of the cell\r\n$(\".highlight\").css({'background-color': \"transparent\" });\r\n                $( '.highlight' ).removeClass( \"highlight\" );\r\n        $(this).css(\"background-color\",\"#CDCDCD\");\r\n        var row = table.row( this ).data()\r\n        $( this ).addClass( \"highlight\" );\r\n        var idfood = row[1];\r\n        var iddrug = row[0];\r\n        var indices=[];\r\n        var idd;\r\n\/\/We get the corresponding id and check if the value sought is in drug or food\r\n        \/\/ then we store them in an array\r\n        if (key.toLowerCase().trim()==idfood.toLowerCase().trim()) {\r\n            idd=iddrug;\r\n        }else if(key.toLowerCase().trim()==iddrug.toLowerCase().trim()){\r\n            idd=idfood;\r\n        }\r\n            for (let i = 0; i < datos['b'].length; i++) {\r\n                if (datos['b'][i]['drug'].toLowerCase().trim()==idd.toLowerCase() || datos['b'][i]['food'].toLowerCase().trim()==idd.toLowerCase()) {\r\n                    indices.push(i);\r\n                }\r\n            }\r\n            $(\".card\").show();\r\n            $(\"#myCarousel\").show();\r\n\r\n           load_data2(indices);\r\n           \r\n        }); \r\n\r\n\r\n\r\n\r\n\/\/Function load_Data 2 to which an array with the values \u200b\u200bto display is passed\r\n        function load_data2(indices){\r\nconsole.log(datos['b']);\r\n            datosarray=[];\r\n            $(\".carousel-indicators\").empty();   \r\n            $(\".carousel-inner\").empty();   \r\n\r\nvar cont=0;\r\n\/\/The values \u200b\u200bare separated and parsed to show it on the screen, since we will paint\r\n\/\/the drug mentioned in red, the food in blue and then a part of the document will be\r\n\/\/in bold, this part is indicated in the database\r\n\/\/Then everything is put into an array to display\r\n            for (let i = 0; i < indices.length; i++) {\r\n                                    datosarray.push(datos['b'][indices[i]]);\r\n                                                    \r\n\r\n                var array = datos['b'][indices[i]];\r\n                var fulltext = (array['document']);\r\n                     sta =datos['b'][indices[i]]['starti'];\r\n                     en =datos['b'][indices[i]]['endi'];\r\n                     documento = fulltext.substr(sta,en);\r\n                     strfood = datos['b'][indices[i]]['food'];\r\n                     strdrug = datos['b'][indices[i]]['drug'];\r\n                     documentostyle = \"<strong>\"+documento+\"<\/strong>\";\r\n                     foodstyle = \"<span style='color:blue;font-size:24px'>\"+ strfood+\"<\/span>\";\r\n                     drugstyle = \"<span style='color:red;font-size:24px'>\"+ strdrug+\"<\/span>\";\r\n                    documentostyle=documentostyle.replace(strfood,foodstyle);\r\n                    documentostyle=documentostyle.replace(strdrug,drugstyle);\r\n                    fulltext=fulltext.replace(documento,documentostyle);\r\n                    \r\n                    \r\n                    \r\n                    \r\n        \r\n    \r\n    \r\n    if(i==0){\r\n                            $(\".carousel-indicators\").append(\"<li  data-target='#myCarousel' data-slide-to='0' class='active'><\/li>\");\r\n                                                        $(\".carousel-inner\").append(\"<div class='carousel-item active' id='carou\"+i+\"'><\/div>\");\r\n\r\n    }    else {\r\n        $(\".carousel-indicators\").append(\"<li  data-target='#myCarousel' data-slide-to='\"+i+\"' ><\/li>\");\r\n                                                        $(\".carousel-inner\").append(\"<div class='carousel-item ' id='carou\"+i+\"'><\/div>\");\r\n    }           \r\n                    $(\"#carou\"+i).append(\"<div class='cardt'><div class='cardcontent d-block w-100' id='card\"+i+\"'><\/div><\/div>\");\r\n                    \/\/$(\"#card\"+i).append(\"<div class='titlestudy'><h1 class='' id=contepar\"+i+\">Total Studies \"+indices.length+\"  Actual Study \"+(i+1)+\"<\/h1><\/div>\");\r\n                    $(\"#card\"+i).append(\"<dl class='' id=conte\"+i+\"><\/dl>\");\r\n                    $(\"#conte\"+i).append(\"<dt class = 'col-sm-3 col-md-6 col-lg-4 col-xl-2'> Food <\/dt>\");\r\n                    $(\"#conte\"+i).append(\"<dd class='col-sm-9 col-md-6 col-lg-8 col-xl-10' > \"+array['food'][0].toUpperCase() + array['food'].substring(1)+\"<\/dd>\");\r\n                    $(\"#conte\"+i).append(\"<dt class = 'col-sm-3 col-md-6 col-lg-4 col-xl-2'> Drug <\/dt>\");\r\n                    $(\"#conte\"+i).append(\"<dd class='col-sm-9 col-md-6 col-lg-8 col-xl-10' > \"+array['drug'][0].toUpperCase() + array['drug'].substring(1)+\"<\/dd>\");\r\n                    $(\"#conte\"+i).append(\"<dt class = 'col-sm-3 col-md-6 col-lg-4 col-xl-2'> Text <\/dt>\");\r\n                    $(\"#conte\"+i).append(\"<dd class='col-sm-9 col-md-6 col-lg-8 col-xl-10' > \" +fulltext+\"<\/dd>\");\r\n                    $(\"#conte\"+i).append(\"<dt class = 'col-sm-3 col-md-6 col-lg-4 col-xl-2'> Link reference <\/dt>\");\r\n                    $(\"#conte\"+i).append(\"<dd class='col-sm-9 col-md-6 col-lg-8 col-xl-10' > <a href=\"+array['link']+\" target='_blank'>\"+array['link']+\"<\/a><\/dd>\");\r\n            }\r\n        \r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\/\/Event when changing number of nodes\r\n$(document).on('keyup', '#edges', function() {\r\n    if (datos['a']['0']!=null){\r\n        nodo();\r\n    }\r\n});\r\n\r\n\r\nfunction nodo(){    \r\n\/\/The network is started by creating the first node in orange color\r\n    var nodes = new vis.DataSet([\r\n        {id: 'id', label: datos['a'][0]['food'] ,  color: \"orange\"}\r\n    ]);\r\n    \/\/Get the number of edges requested by the user\r\n  var nedges=$(\"#edges\").val();\r\n  var size = datos['a'].length-1;\r\n\/\/if the number of edges is greater than the length of the array, the length will be used as the maximum value of edges\r\n  if (nedges>datos['a'][size]['num']) {\r\n      nedges=datos['a'][size]['num'];\r\n  }\r\n  var cont = 0;\r\n  var edges = new vis.DataSet();\r\n  var xboo=false;\r\n\/\/ The node is obtained and it is compared to know if the drug or the food is the key sought to paint it in one color or another\r\n  \/\/ After that, the edges will also be made, if the drug has the number 1 and the next one has the number 4, it will be necessary to paint 3 edges for that node\r\n  \/\/With the variable 'xboo' this will be verified\r\n  if ( datos['a'][cont]['num'] > 1 ) {\r\n    if(datos['a'][cont]['drug']==keydata){\r\n                   nodes.add([ \r\n        {id: datos['a'][cont]['num'], label: datos['a'][cont]['food'],color:\"orange\"},\r\n    ]);\r\n    edges.add([\r\n      {from: 'id', to: datos['a'][cont]['num'],color:\"rgb(221,160,221)\"},\r\n    ]);\r\n       }else{\r\n            nodes.add([ \r\n        {id: datos['a'][cont]['num'], label: datos['a'][cont]['drug'],color:\"rgb(221,160,221)\"},\r\n    ]);\r\n    edges.add([\r\n      {from: 'id', to: datos['a'][cont]['num'],color:\"orange\"},\r\n    ]);\r\n       }\r\n       cont++;\r\n  }\r\n  for (let i = 0; i < nedges; i++) {\r\n\r\n   if ((i+1) == datos['a'][cont]['num']) {\r\n       if(datos['a'][cont]['drug']==keydata){\r\n                   nodes.add([ \r\n        {id: datos['a'][cont]['num'], label: datos['a'][cont]['food'],color:\"orange\"},\r\n    ]);\r\n    edges.add([\r\n      {from: 'id', to: datos['a'][cont]['num'],color:\"rgb(221,160,221)\"},\r\n    ]);\r\n       }else{\r\n            nodes.add([ \r\n        {id: datos['a'][cont]['num'], label: datos['a'][cont]['drug'],color:\"rgb(221,160,221)\"},\r\n    ]);\r\n    edges.add([\r\n      {from: 'id', to: datos['a'][cont]['num'],color:\"orange\"},\r\n    ]);\r\n       }\r\n      xboo=true;\r\n   }else {\r\n\r\n       if(datos['a'][(cont-1)]['drug']==keydata){\r\n          edges.add([\r\n      {from: 'id', to: datos['a'][(cont-1)]['num'],color:\"rgb(221,160,221)\"},\r\n    ]);\r\n           \r\n       }else{ \r\n edges.add([\r\n      {from: 'id', to: datos['a'][(cont-1)]['num']},\r\n    ])}\r\n   }\r\n\r\n    \r\n    \r\n   if(xboo==true){\r\n     cont++;\r\n     xboo=false;\r\n   }\r\n  }\r\n\r\n    \r\n    \r\n   if(xboo==true){\r\n     cont++;\r\n     xboo=false;\r\n   }\r\n\r\n \/\/ create a network\r\n    var container = document.getElementById('mynetwork');\r\n\r\n    \/\/ provide the data in the vis format\r\n    var data = {\r\n        nodes: nodes,\r\n        edges: edges\r\n    };\r\n    var options = {};\r\n\r\n    \/\/ initialize your network!\r\n    var network = new vis.Network(container, data, options);\r\n\r\n\r\n\r\n  var mynetwork = document.getElementById(\"mynetwork\");\r\nvar x = -mynetwork.offsetWidth\/2;\r\nvar step = 70;\r\n  nodes.add({\r\n    id: 1000000000,\r\n    x: x,\r\n    y: -300,\r\n    shape: \"square\",\r\n    color:\"rgb(221,160,221)\",\r\n    label: \"DRUG \",\r\n    group: \"drug\",\r\n    size: 20,\r\n    value: 1,\r\n    fixed: true,\r\n    physics: false,\r\n  });\r\n  nodes.add({\r\n    id: 1000000001,\r\n    x: x,\r\n    y: -300 + step,\r\n     shape: \"square\",\r\n    color:\"orange\",\r\n    label: \"FOOD\",\r\n    group: \"food\",\r\n     size: 20,\r\n    value: 1,\r\n    fixed: true,\r\n    physics: false,\r\n  });\r\n\r\nnetwork.on( 'click', function(properties) {\r\n    var ids = properties.nodes;\r\n    var clickedNodes = nodes.get(ids);\r\n    $('.dataTables_filter input').val(clickedNodes[0]['label']);\r\n    table.search( clickedNodes[0]['label'] ).draw();\r\n      $(\".dataTables_filter input\").trigger(\"focus\");\r\n\/*   var valor=-1;\r\n   for (let index = 0; index < datanew.length; index++) {\r\n    if(datanew[index]['drug']==clickedNodes[0]['label'] || datanew[index]['food']==clickedNodes[0]['label']){\r\n        valor=index;\r\n    }\r\n}\r\n   $('#content1'+valor).click();*\/\r\n});\r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\n$(document).on('click', '.btn-secondary', function() {\r\n        \/\/Get the page where you are and what type of download it iss\r\n           var subid= $(this).attr(\"id\");\r\n\/\/Copy with the obtained data, with this it is added to an input and the copy command is executed later the input is deleted\r\n            \/\/ With this is on the clipboard\r\n\/\/We remove the fields from the strati num text yendi array so that there is no information \/\/irrelevant for the user\r\n            if (subid == \"copy\" ) {\r\n                dataacopiar=[];\r\n                copy=\"\";\r\n                            for (let i = 0; i < datosarray.length || i  < 10 ; i++) {\r\n                                dataacopiar[i]={};\r\n            for (var  dato in datosarray[i]){\r\n        if(dato != \"starti\" && dato != \"num\" && dato != \"text\" && dato != \"endi\"){\r\n            copy=copy+datosarray[i][dato];\r\n}\r\n}\r\n}\r\n                    $('<input id=\"textcopy\">').val(copy).appendTo('body').select();         \r\n            document.execCommand('copy'); \r\n            var el = document.getElementById('textcopy');\r\n            el.remove();\r\n            }\r\n                                    \/\/TSV OR CSV the file is sent to descargararchivo.php and the associative array is sent\r\n            else {\r\n                dataacopiar=[];\r\n                            for (let i = 0; i < datosarray.length; i++) {\r\n                                dataacopiar[i]={};\r\n            for (var  dato in datosarray[i]){\r\n        if(dato != \"starti\" && dato != \"num\" && dato != \"text\" && dato != \"endi\"){\r\n            \r\n    dataacopiar[i][dato]=datosarray[i][dato];\r\n}\r\n}\r\n}\r\n\r\n                $.ajax({\r\n            url:'https:\/\/imdeafoodcompubio.com\/wp-content\/themes\/bento-child\/descargararchivo.php',\r\n            type: 'post',\r\n            data: {key:subid,data:dataacopiar,name:\"tabletextmining\"},\r\n            dataType: 'json',\r\n            success:function(response){\r\n                                \/\/Get the name of the file which is on the response and create an element <a> and add the attribute\r\n                \/\/'download'  and indicate where the file is located and order the element to be clicked\r\n                \/\/and start the download\r\n                \r\n                fileName=response;\r\n               \r\n                        fileUrl=\"http:\/\/imdeafoodcompubio.com\/wp-content\/uploads\/2022\/desc\/\"+fileName;\r\n  var a = document.createElement(\"a\");\r\n  a.href = fileUrl;\r\n  a.setAttribute(\"download\", fileName);\r\n  a.click();\r\n               \r\n            }\r\n                });\r\n            \r\n\r\n\r\n            }\r\n            });\r\n\r\n\r\n\r\n\r\n\r\n});\r\n\r\n\r\n <\/script>\r\n\r\n<\/body>\r\n<\/html>\r\n<\/html>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-16","page","type-page","status-publish","hentry","no-thumb"],"_links":{"self":[{"href":"https:\/\/imdeafoodcompubio.com\/index.php\/wp-json\/wp\/v2\/pages\/16","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/imdeafoodcompubio.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/imdeafoodcompubio.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/imdeafoodcompubio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/imdeafoodcompubio.com\/index.php\/wp-json\/wp\/v2\/comments?post=16"}],"version-history":[{"count":6,"href":"https:\/\/imdeafoodcompubio.com\/index.php\/wp-json\/wp\/v2\/pages\/16\/revisions"}],"predecessor-version":[{"id":606,"href":"https:\/\/imdeafoodcompubio.com\/index.php\/wp-json\/wp\/v2\/pages\/16\/revisions\/606"}],"wp:attachment":[{"href":"https:\/\/imdeafoodcompubio.com\/index.php\/wp-json\/wp\/v2\/media?parent=16"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}