All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.houbb.value.extraction.test.bs.PythonTest Maven / Gradle / Ivy

The newest version!
package com.github.houbb.value.extraction.test.bs;

import com.github.houbb.value.extraction.core.bs.ValueExtractionBs;
import com.github.houbb.value.extraction.core.support.extraction.ValueExtractions;
import org.junit.Assert;
import org.junit.Test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class PythonTest {

    @Test
    public void test() {
        // 创建绑定并设置参数
        Map data = new HashMap<>();
        data.put("original_string", "This is a very long string that needs to be truncated.");
        data.put("max_length", 20);

        // 定义 JavaScript 脚本
        String script = "original_string = dataMap['original_string']\n" +
                "max_length = dataMap['max_length']\n" +
                "result = original_string[:max_length]\n" +
                "if len(original_string) > max_length:\n" +
                "    result += '...'";

        Map resultMap = ValueExtractionBs.newInstance()
                .scripts(Arrays.asList(script))
                .valueExtraction(ValueExtractions.python())
                .dataMap(data)
                .extract();

        Assert.assertEquals("[This is a very long ...]", resultMap.values().toString());
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy