Git Product home page Git Product logo

Comments (1)

satpalsr avatar satpalsr commented on May 18, 2024

Hi @AymenBenk

slack is a list containing a single element and hence you can't do slack.aspect.

One workaround to extract weights, scores and aspect could be as following:

# Convert slack from list to string.
slack = str(slack)

import re
# Replace suitable characters with new line characters.
wei = slack.replace(")", " \n ")
sco = slack.replace("]", " \n ")
asp = slack.replace(",", " \n ")

# Find out the weights, scores and aspect in the above 3 strings.
weights = re.findall(r"\bwei.*", wei)
scores = re.search(r"\bsco.*", sco)
scores = str(scores.group()) + "]"
aspec = re.search(r"\basp.*", asp)

print(weights)
print(scores)
print(aspec.group())

# Results are as following:
['weights=[0.28, 1.0, 0.71] ', 'weights=[0.13, 0.58, 0.58] ', 'weights=[0.25, 0.25, 0.17] ']
scores=[0.0005469012, 0.0009526044, 0.99850047 ]
aspect='mascara' 

The second better approach is:

an_string = str(slack)

# Extract aspect
aspect = an_string.split('aspect=')[1].split(',')[0]
print("aspect", aspect)

# Extract scores
scores = an_string.split("scores=[")[1].split("]")[0].split(",")
scores = [float(score) for score in scores]
print("scores", scores)

# Extract weights
def extract_weights(an_string,i):
    weights = an_string.split("weights=[")[i].split("]")[0].split(",")
    weights = [float(weight) for weight in weights]
    print(weights)

print("weights")
extract_weights(an_string,1)
extract_weights(an_string,2)
extract_weights(an_string,3)

# Results are as following:
aspect 'mascara'
scores [0.0005469007, 0.0009526035, 0.99850047]
weights
[0.28, 1.0, 0.71]
[0.13, 0.58, 0.58]
[0.25, 0.25, 0.17]

from aspect-based-sentiment-analysis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.