easyrec data organization

easyrec: A recommendation system for a java library!

One: environment construction

Install JDK and JRE, respectively, in two folders (jdk, jre) under the same folder (java)

System variable configuration: 1: New system JAVA_HOME variable → F:/java/jdk

  2: System Path Variables→Edit Add→%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;

  3: New system CLASSPATH variable→.;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar

  4: Verify that the configuration is successful, run cmd and enter java -version


Install Tomcat (open source free java web server)

  1: Download address: http://tomcat.apache.org/

  2: Environment variable configuration: New system CATALINA_HOME variable → F:\Tomcat\tomcat

  3: cmd enters the bin directory in the installation directory and executes service.bat install (removed as service.bat remove)

  4: Double-click to run tomcat8w.exe in the bin directory to start

  5: Enter localhost:8080 in the browser, if you can enter the Tomcat control home page, the installation is successful


Enter the Tomcat control home page, enter the Manger App (enter the user name and password)

The first time you enter, you need to set it up (F:\Tomcat\tomcat\conf\tomcat-users.xml) and add the following code

<role rolename="manager-gui"/>
<user username="tomcat" password="s3cret" roles="manager-gui"/>

After closing, restart tomcat8w.exe, and log in with the corresponding user name and password after entering again.

In the Deploy column, directly deploy the easyrec project file (easyrec-web.war can be obtained after downloading the corresponding version from the official website and decompressing it)

After the deployment is complete, enter http://localhost:8080/easyrec-web/ in the browser address bar to enter the configuration stage (4 steps, if there is no fourth step)

innodb_flush_log_at_trx_commit=0

innodb_buffer_pool_size=1024M

innodb_log_file_size=250M

innodb_log_buffer_size=16M

Enter under [mysqld] in my.ini

sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

After saving, restart the service. Configure again (make sure that the redirection can be successful after completion, if it fails, it is usually ONLY_FULL_GROUP_BY in sql_mode, just remove it)

2: After the redirection is successful (you need to enter http://localhost:8080/easyrec-web/ to log in in the future, enter the user name and password to log in)

Create a new tenant, you can directly use the created tenant (one tenant corresponds to one project) to make interface calls and subsequent processing

The use of easyrec is generally divided into: the setting stage and the use stage (the algorithm is built-in, as long as it is used). After logging in, you can view it under the API (the former is the Wikipedia details of API interface calls, and the latter is the details of JS interface calls, generally use the first)

Setting stage: instant token acquisition, itemtype setting, product addition, relationship setting between products, etc.

Use stage: commonly used by others, user history, most viewed by the community, recommendation for users, user action sending, etc.

Three: Table structure and table field description: refer to https://wenku.baidu.com/view/7cd8ad0b83c4bb4cf7ecd1aa.html

Four: Attention! The priority recommendation level of VIEWED_TOGETHER is the highest, which is much higher than IS_RELATED. The former relationship value of 10 is recommended first than the latter relationship value of 100. When multiple relationships point to the same product, the recommendation level will be set to the highest, even if his relationship Values ​​are average calculations. (The specifics are determined by the internal algorithm)

Five: a class called by a common interface that I encapsulate

class EasyRec{
    protected $apikey="";//API key

    protected $tenantid="";//Tenant ID to identify your website

    protected $username="";//Background login username

    protected $password="" ;//Background login password

    protected $serverUrl="http://localhost:8080/easyrec-web";//easyrec project address

    //encapsulate curl request, just use get request
    public function easy($url){
        / /Create curl
        $ch=curl_init();
        //Set curl
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
        //Execute curl
        $output=curl_exec($ch);
        // close curl
        curl_close($ch);
        return $output;
    }

    /**
     * [Generate instant token]
     * @return [string] [latest token]
     */
    public function token(){
        //splicing interface url
        $url_token="{$this->serverUrl}/operator/signin?operatorId={$ this->username}&password={$this->password}";

        //Get an XML result
        $res= $this->easy($url_token);
        //Convert XML into json object first, then into array , take out the token
        $res=json_decode(json_encode(simplexml_load_string($res)),true);
        //return the token string
        return $res["token"];
    }

    /**
     * [Add itemType: only uppercase is allowed, no It will be added repeatedly]
     * @param [type] $itemtype [product/article type]
     */
    public function addType($itemtype){
        $url_addType="{$this->serverUrl}/api/1.0/additemtype?apikey={$this->apikey}&tenantid={$this->tenantid}&itemtype={$itemtype}";

        $res=$this- >easy($url_addType);
        //Success returns an empty string''
        return $res;
    }

    //Delete itemType
    public function deleteType(){
        //Deleting a type will delete all related operations, rules, etc., generally not selected delete
    }

    /**
     * [Import or update articles/items]
     * @param [type] $itemid [article ID]
     * @param [type] $itemdescription [article description] urlencode("test 10"), article title
     * @ param [type] $itemurl [article details page address] urlencode("/item/article")
     * @param [type] $itemimageurl [article image address] urlencode("/img/covers/hua.jpg")
     * @param [type] $itemtype [article type, default ITEM]
     */
    public function addItem($itemid,$itemdescription,$itemurl="",$itemimageurl="",$itemtype="ITEM"){
        //Add Or when modifying articles or products, you need to use token
        $token=$this->token();
        //splicing interface url
        $url_add="{$this->serverUrl}/api/1.0/importitem?token={$token} &tenantid={$this->tenantid}&itemid={$itemid}&itemdescription={$itemdescription}&itemurl={$itemurl}&itemimageurl={$itemimageurl}&itemtype={$itemtype}";
        //Initiate request
        $res=$this ->easy($url_add);
        return $res;
    }

    /**
     * [rule import]
     * @param [type] $itemfromid [from item]
     * @param [type] $itemtoid [to item]
     * @param [type] $assoctype [association type] generally use the first two (default VIEWED_TOGETHER)
     * VIEWED_TOGETHER, IS_RELATED, PROFILE_SIMILARITY, GOOD_RATED_TOGETHER, BOUGHT_TOGETHER
     * @param [type] $assocvalue [association value 0.0 to 100] default 100
     * @ param [type] $itemfromtype [from item type] default ITEM
     * @param [type] $itemtotype [to item type] default ITEM
     * @return [string] [description]
     */
    public function rule($itemfromid,$itemtoid,$ assoctype="VIEWED_TOGETHER",$assocvalue=100,$itemfromtype="ITEM",$itemtotype="ITEM"){
        //You need to use token when importing rules
        $token=$this->token();

        $url_rule="{$this->serverUrl}/api/1.0/importrule?token={$token}&tenantid={$this->tenantid}&itemfromid={$itemfromid}&itemfromtype={$itemfromtype}&itemtoid={$itemtoid }&itemtotype={$itemtotype}&assoctype={$assoctype}&assocvalue={$assocvalue}";

        $res=$this->easy($url_rule);
        return $res;
    }

    /**
     * [Send View Action]
     * @ param [string] $apikey [API key]
     * @param [string] $tenantid [tenant ID to identify your site]
     * @param [string] $userid [current user ID] "24EH1723322222Z1"
     * @param [string] $sessionid [user session id] "F3D4E3BE31EE3FA069F5434DB7EC2E01"
     * @param [string] $itemid [article/item ID]
     * @param [string] $itemdescription [item description] urlencode The article title of the article table
     * @param [string] $itemurl [link to article/item detail page] urlencode("/item/article") default""
     * @param [string] $itemimageurl [image of item] urlencode("/img/covers/ hua.jpg")default""
     * @return [string] [information about the user viewing the article]
     */
    public function view($userid,$sessionid,$itemid,$itemdescription,$itemurl="",$itemimageurl="" ){
        //Splicing interface url
        $url_view="{$this->serverUrl}/api/1.0/view?apikey={$this->apikey}&tenantid={$this->tenantid}&itemid={$itemid}&itemdescription ={$itemdescription}&itemurl={$itemurl}&itemimageurl={$itemimageurl}&userid={$userid}&sessionid={$sessionid}";
        //Initiate a request
        return $this->easy($url_view);

    }

    /**
     * [Get recommended information (return up to 15, the results are sorted by relevance)]
     * @param [type] $apikey [API key]
     * @param [type] $tenantid [tenant ID to identify your site]
     * @param [type] $userid [current user ID] "24EH1723322222Z1"
     * @param integer $numberOfResults [Number of records returned, default returns 15]
     * @param string $requesteditemtype [Recommended product or article type, default ITEM]
     * @return [json] [The obtained recommendation information]
     */
    public function rec($userid ,$numberOfResults=15,$requesteditemtype="ITEM"){
        //Splicing interface url
        $url_rec="{$this->serverUrl}/api/1.0/json/recommendationsforuser?apikey={$this->apikey}&tenantid= {$this->tenantid}&userid={$userid}&numberOfResults={$numberOfResults}&requesteditemtype={$requesteditemtype}";
        //Initiate request
        return $this->easy($url_rec);
    }

    /**
     * [get history]
     * @param [type] $apikey [API key]
     * @param [type] $tenantid [tenant ID to identify your site ]
     * @param [type] $userid [current user ID] "24EH1723322222Z1"
     * @param [type] $numberOfResults [number of records returned, 15 by default]
     * @return [json] [get history records]
     */
    public function history($userid,$numberOfResults=15){
        //Splicing interface url
        $url_histo="{$this->serverUrl}/api/1.0/json/actionhistoryforuser?apikey={$this->apikey}&tenantid={$this ->tenantid}&userid={$userid}&numberOfResults={$numberOfResults}";
        //Initiate a request
        return $this->easy($url_histo);
    }

    /**
     * [Get the most viewed]
     * @param string $timeRange [Time range: (DAY, WEEK, MONTH, ALL)]
     * @param integer $numberOfResults [Number of records returned, 50 by default]
     * @return [ type] [description]
     */
    public function most($timeRange="All",$numberOfResults=50){
        //Splicing interface url
        $url_most="{$this->serverUrl}/api/1.0/json/mostvieweditems?apikey ={$this->apikey}&tenantid={$this->tenantid}&timeRange={$timeRange}&numberOfResults={$numberOfResults}";
        //Initiate a request
        return $this->easy($url_most);
    }

}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326681620&siteId=291194637