stuzha 0.2.2__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {stuzha-0.2.2 → stuzha-0.2.4}/PKG-INFO +1 -1
- {stuzha-0.2.2 → stuzha-0.2.4}/setup.py +2 -1
- {stuzha-0.2.2 → stuzha-0.2.4}/stuzha/BF.py +136 -57
- {stuzha-0.2.2 → stuzha-0.2.4}/stuzha/IoT.py +9 -12
- {stuzha-0.2.2 → stuzha-0.2.4}/stuzha/NLP.py +185 -2
- {stuzha-0.2.2 → stuzha-0.2.4}/stuzha/SNA.py +42 -10
- {stuzha-0.2.2 → stuzha-0.2.4}/stuzha.egg-info/PKG-INFO +1 -1
- {stuzha-0.2.2 → stuzha-0.2.4}/stuzha.egg-info/entry_points.txt +1 -0
- {stuzha-0.2.2 → stuzha-0.2.4}/setup.cfg +0 -0
- {stuzha-0.2.2 → stuzha-0.2.4}/stuzha/__init__.py +0 -0
- {stuzha-0.2.2 → stuzha-0.2.4}/stuzha.egg-info/SOURCES.txt +0 -0
- {stuzha-0.2.2 → stuzha-0.2.4}/stuzha.egg-info/dependency_links.txt +0 -0
- {stuzha-0.2.2 → stuzha-0.2.4}/stuzha.egg-info/requires.txt +0 -0
- {stuzha-0.2.2 → stuzha-0.2.4}/stuzha.egg-info/top_level.txt +0 -0
|
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|
|
2
2
|
|
|
3
3
|
setup(
|
|
4
4
|
name='stuzha',
|
|
5
|
-
version='0.2.
|
|
5
|
+
version='0.2.4',
|
|
6
6
|
packages=find_packages(),
|
|
7
7
|
install_requires=[
|
|
8
8
|
'colorama>=0.4.6',
|
|
@@ -51,6 +51,7 @@ setup(
|
|
|
51
51
|
'fb_7 = stuzha.BF:fb_7',
|
|
52
52
|
'fb_8 = stuzha.BF:fb_8',
|
|
53
53
|
'fb_9 = stuzha.BF:fb_9',
|
|
54
|
+
'fb_10 = stuzha.BF:fb_10',
|
|
54
55
|
],
|
|
55
56
|
}
|
|
56
57
|
)
|
|
@@ -261,6 +261,7 @@ print("Current hash:", genesis_block.hash)
|
|
|
261
261
|
|
|
262
262
|
|
|
263
263
|
|
|
264
|
+
|
|
264
265
|
# User input single block one transaction
|
|
265
266
|
|
|
266
267
|
|
|
@@ -458,7 +459,6 @@ print("\nBlock added to the blockchain:")
|
|
|
458
459
|
print(block)
|
|
459
460
|
|
|
460
461
|
|
|
461
|
-
|
|
462
462
|
|
|
463
463
|
''')
|
|
464
464
|
|
|
@@ -704,12 +704,6 @@ if __name__ == "__main__":
|
|
|
704
704
|
print(json.dumps(block, indent=4), "\n")
|
|
705
705
|
|
|
706
706
|
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
707
|
''')
|
|
714
708
|
|
|
715
709
|
def fb_5():
|
|
@@ -937,17 +931,6 @@ contract SimpleArray {
|
|
|
937
931
|
}
|
|
938
932
|
}
|
|
939
933
|
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
934
|
''')
|
|
952
935
|
|
|
953
936
|
def fb_6():
|
|
@@ -1292,25 +1275,33 @@ contract multiplemodifier {
|
|
|
1292
1275
|
pragma solidity ^0.8;
|
|
1293
1276
|
|
|
1294
1277
|
contract StructExample {
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1278
|
+
struct Employee {
|
|
1279
|
+
uint emp_id;
|
|
1280
|
+
string emp_name;
|
|
1281
|
+
uint age;
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
uint[] public dynamicArray;
|
|
1285
|
+
|
|
1286
|
+
function add(uint value) public {
|
|
1287
|
+
dynamicArray.push(value);
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
function getArray() public view returns (uint[] memory) {
|
|
1291
|
+
return dynamicArray;
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
function staticArrayExample() public pure returns (uint) {
|
|
1295
|
+
uint[3] memory c = [uint(1), 2, 3];
|
|
1296
|
+
assert(c.length == 3);
|
|
1297
|
+
return c.length;
|
|
1298
|
+
}
|
|
1307
1299
|
}
|
|
1308
1300
|
|
|
1309
1301
|
|
|
1310
1302
|
|
|
1311
1303
|
|
|
1312
1304
|
|
|
1313
|
-
|
|
1314
1305
|
# Error handling in Solidity
|
|
1315
1306
|
|
|
1316
1307
|
## Using require
|
|
@@ -1384,15 +1375,6 @@ contract RevertStatement {
|
|
|
1384
1375
|
}
|
|
1385
1376
|
}
|
|
1386
1377
|
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
1378
|
''')
|
|
1397
1379
|
|
|
1398
1380
|
def fb_7():
|
|
@@ -1400,9 +1382,10 @@ def fb_7():
|
|
|
1400
1382
|
|
|
1401
1383
|
# Launch Ganache and create a new workspace.
|
|
1402
1384
|
# Download and extract MyEtherWallet v3.11.2.4 and open the index.html file.
|
|
1403
|
-
# Add a custom node by getting the RPC Server Address from Ganache.
|
|
1404
|
-
# Navigate to contracts and select “Deploy Contract”
|
|
1405
|
-
|
|
1385
|
+
# Add a custom node in MyEtherWallet by getting the RPC Server Address from Ganache.
|
|
1386
|
+
# Navigate to contracts on MyEtherWallet and select “Deploy Contract”
|
|
1387
|
+
|
|
1388
|
+
# Write the below CRUD smart contract in Remix IDE
|
|
1406
1389
|
|
|
1407
1390
|
|
|
1408
1391
|
|
|
@@ -1478,9 +1461,9 @@ contract Crud {
|
|
|
1478
1461
|
|
|
1479
1462
|
# Compile the smart contract using compiler version 0.5.17+commit.d19bba13 and copy the generated bytecode.
|
|
1480
1463
|
# Paste the byte code in the previously opened “Deployed Contract” page of MyEtherWallet.
|
|
1481
|
-
# Copy the private key from one of the accounts from Ganache and paste it in MyEtherWallet and
|
|
1464
|
+
# Copy the private key from one of the accounts from Ganache by pressing the key icon and paste it in MyEtherWallet and unlock the wallet.
|
|
1482
1465
|
# Sign the transaction and deploy the contract.
|
|
1483
|
-
# Verify the contract creation in Ganache.
|
|
1466
|
+
# Verify the contract creation in Ganache (In the transactions tab).
|
|
1484
1467
|
# Select “Interact with Contract” on MyEtherWallet.
|
|
1485
1468
|
# Copy and paste the created Contract address from Ganache along with the generated ABI from Remix IDE.
|
|
1486
1469
|
# Click access to view the smart contract functions.
|
|
@@ -1667,6 +1650,28 @@ app.run(host='0.0.0.0', port=5001)
|
|
|
1667
1650
|
|
|
1668
1651
|
|
|
1669
1652
|
|
|
1653
|
+
|
|
1654
|
+
# GET
|
|
1655
|
+
# localhost:5001/get_chain
|
|
1656
|
+
|
|
1657
|
+
# POST
|
|
1658
|
+
# localhost:5001/add_transaction
|
|
1659
|
+
# Body:
|
|
1660
|
+
{
|
|
1661
|
+
"sender": "abc",
|
|
1662
|
+
"receiver": "xyz",
|
|
1663
|
+
"amount": "10"
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
|
|
1667
|
+
# GET
|
|
1668
|
+
# localhost:5001/mine_block
|
|
1669
|
+
|
|
1670
|
+
# GET
|
|
1671
|
+
# localhost:5001/get_chain
|
|
1672
|
+
|
|
1673
|
+
|
|
1674
|
+
|
|
1670
1675
|
''')
|
|
1671
1676
|
|
|
1672
1677
|
def fb_9():
|
|
@@ -2030,6 +2035,80 @@ app.run(host='0.0.0.0', port=5002)
|
|
|
2030
2035
|
|
|
2031
2036
|
|
|
2032
2037
|
|
|
2038
|
+
|
|
2039
|
+
|
|
2040
|
+
|
|
2041
|
+
# Connect node 1 to node 2
|
|
2042
|
+
|
|
2043
|
+
# POST
|
|
2044
|
+
# localhost:5001/connect_nodes
|
|
2045
|
+
|
|
2046
|
+
{
|
|
2047
|
+
"nodes": [
|
|
2048
|
+
"http://127.0.0.1:5002"
|
|
2049
|
+
]
|
|
2050
|
+
}
|
|
2051
|
+
|
|
2052
|
+
|
|
2053
|
+
|
|
2054
|
+
# Connect node 2 to node 1
|
|
2055
|
+
|
|
2056
|
+
# POST
|
|
2057
|
+
# localhost:5002/connect_nodes
|
|
2058
|
+
|
|
2059
|
+
{
|
|
2060
|
+
"nodes": [
|
|
2061
|
+
"http://127.0.0.1:5001"
|
|
2062
|
+
]
|
|
2063
|
+
}
|
|
2064
|
+
|
|
2065
|
+
|
|
2066
|
+
|
|
2067
|
+
# GET
|
|
2068
|
+
# localhost:5001/get_chain
|
|
2069
|
+
|
|
2070
|
+
# POST
|
|
2071
|
+
# localhost:5001/add_transaction
|
|
2072
|
+
|
|
2073
|
+
{
|
|
2074
|
+
"sender": "abc",
|
|
2075
|
+
"receiver": "xyz",
|
|
2076
|
+
"amount": "10"
|
|
2077
|
+
}
|
|
2078
|
+
|
|
2079
|
+
|
|
2080
|
+
# GET
|
|
2081
|
+
# localhost:5001/mine_block
|
|
2082
|
+
|
|
2083
|
+
|
|
2084
|
+
# GET
|
|
2085
|
+
# localhost:5001/get_chain
|
|
2086
|
+
|
|
2087
|
+
|
|
2088
|
+
# GET
|
|
2089
|
+
# localhost:5002/get_chain
|
|
2090
|
+
|
|
2091
|
+
|
|
2092
|
+
# GET
|
|
2093
|
+
# localhost:5002/replace_chain
|
|
2094
|
+
|
|
2095
|
+
# POST
|
|
2096
|
+
# localhost:5002/add_transaction
|
|
2097
|
+
|
|
2098
|
+
{
|
|
2099
|
+
"sender": "Alice",
|
|
2100
|
+
"receiver": "Carl",
|
|
2101
|
+
"amount": "50"
|
|
2102
|
+
}
|
|
2103
|
+
|
|
2104
|
+
|
|
2105
|
+
# GET
|
|
2106
|
+
# localhost:5002/mine_block
|
|
2107
|
+
|
|
2108
|
+
# GET
|
|
2109
|
+
# localhost:5002/get_chain
|
|
2110
|
+
|
|
2111
|
+
Get chain node 1 and replace chain on node 1
|
|
2033
2112
|
|
|
2034
2113
|
''')
|
|
2035
2114
|
|
|
@@ -2041,26 +2120,26 @@ def fb_10():
|
|
|
2041
2120
|
# Navigate to settings and enable “Show test networks” in the Advanced section of the settings.
|
|
2042
2121
|
# Now select Sepolia as the test network from Custom networks
|
|
2043
2122
|
|
|
2044
|
-
# Go to Google Ethereum Sepolia Faucet, sign in and enter the MetaMask Sepolia wallet address to get the Ethereum tokens.
|
|
2123
|
+
# Go to Google Ethereum Sepolia Faucet, sign in and enter the MetaMask Sepolia wallet address to get the Ethereum tokens. (Get the Ethereum address by pressing the receive button on metamask)
|
|
2045
2124
|
|
|
2046
|
-
# View the added tokens in MetaMask
|
|
2125
|
+
# View the added tokens in MetaMask
|
|
2126
|
+
# Go to Remix IDE to connect the Sepolia Testnet - MetaMask wallet in the browser extension section of the environment.
|
|
2047
2127
|
# Compile the smart contract and deploy it.
|
|
2048
2128
|
|
|
2049
2129
|
|
|
2050
2130
|
|
|
2051
2131
|
// SPDX-License-Identifier: MIT
|
|
2052
2132
|
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
2133
|
pragma solidity ^0.8.0;
|
|
2056
2134
|
contract SimpleStorage {
|
|
2057
|
-
uint256 private storedData;
|
|
2058
|
-
function set(uint256 x) public {
|
|
2059
|
-
storedData = x;
|
|
2060
|
-
}
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2135
|
+
uint256 private storedData;
|
|
2136
|
+
function set(uint256 x) public {
|
|
2137
|
+
storedData = x;
|
|
2138
|
+
}
|
|
2139
|
+
|
|
2140
|
+
function get() public view returns (uint256) {
|
|
2141
|
+
return storedData;
|
|
2142
|
+
}
|
|
2064
2143
|
}
|
|
2065
2144
|
|
|
2066
2145
|
|
|
@@ -2098,7 +2177,7 @@ const contractABI = [
|
|
|
2098
2177
|
"function set(uint256 x) public",
|
|
2099
2178
|
"function get() public view returns (uint256)",
|
|
2100
2179
|
];
|
|
2101
|
-
const contractAddress = "
|
|
2180
|
+
const contractAddress = "0x077980e4Bd973BbE2Daf6516c970b1C586d6C809";
|
|
2102
2181
|
let provider;
|
|
2103
2182
|
let signer;
|
|
2104
2183
|
let contract;
|
|
@@ -164,6 +164,12 @@ python -m apache_beam.examples.wordcount --output outputs
|
|
|
164
164
|
|
|
165
165
|
# Run the wordcount pipeline on Cloud Dataflow.
|
|
166
166
|
|
|
167
|
+
python -m apache_beam.examples.wordcount --region asia-south2 --input gs://dataflow-samples/shakespeare/kinglear.txt --output gs://p4-cloud-dataflow-pipeline/results/outputs --runner DataflowRunner --project p4-cloud-dataflow-pipeline --temp_location gs://p4-cloud-dataflow-pipeline/tmp
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
# Alternate command
|
|
172
|
+
|
|
167
173
|
|
|
168
174
|
python -m apache_beam.examples.wordcount \
|
|
169
175
|
--region asia-south1 \
|
|
@@ -179,16 +185,10 @@ python -m apache_beam.examples.wordcount \
|
|
|
179
185
|
|
|
180
186
|
|
|
181
187
|
|
|
182
|
-
# Verify the pipeline execution.
|
|
183
|
-
# View the output in the cloud storage bucket.
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
188
|
|
|
191
189
|
|
|
190
|
+
# Verify the pipeline execution.
|
|
191
|
+
# View the output in the cloud storage bucket.
|
|
192
192
|
|
|
193
193
|
''')
|
|
194
194
|
|
|
@@ -283,6 +283,7 @@ def cp_6():
|
|
|
283
283
|
#include "thingProperties.h"
|
|
284
284
|
|
|
285
285
|
int LED_BUILTIN = 2;
|
|
286
|
+
|
|
286
287
|
void setup() {
|
|
287
288
|
Serial.begin(9600);
|
|
288
289
|
delay(1500);
|
|
@@ -304,10 +305,6 @@ void onIsPoweredChange() {
|
|
|
304
305
|
digitalWrite(LED_BUILTIN, is_powered);
|
|
305
306
|
}
|
|
306
307
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
308
|
''')
|
|
312
309
|
|
|
313
310
|
def cp_7():
|
|
@@ -4,7 +4,10 @@ init(autoreset=True)
|
|
|
4
4
|
|
|
5
5
|
def pln_1():
|
|
6
6
|
print(Fore.RED + '''
|
|
7
|
+
|
|
8
|
+
# pip install nltk matplotlib
|
|
7
9
|
|
|
10
|
+
|
|
8
11
|
import nltk
|
|
9
12
|
|
|
10
13
|
nltk.download('punkt')
|
|
@@ -123,10 +126,23 @@ course_pattern = r'([0-9]+)\s*([A-Z]{3})\s*([A-Za-z]{4,})'
|
|
|
123
126
|
|
|
124
127
|
re.findall(course_pattern, text)
|
|
125
128
|
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
# Find "Cool"
|
|
132
|
+
|
|
126
133
|
print(re.findall(r'Co+l', 'So Cooool Coool Cool coool col'))
|
|
127
134
|
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
# Find 'toy'
|
|
138
|
+
|
|
128
139
|
re.findall(r'\btoy\b', 'play toy broke toys')
|
|
129
140
|
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
# Regular Expression for email ID
|
|
145
|
+
|
|
130
146
|
emails = """adityagoriwale@facebook.com
|
|
131
147
|
irminsul@google.com
|
|
132
148
|
Deez@amazon.com"""
|
|
@@ -135,6 +151,9 @@ re.findall(pattern, emails, flags=re.IGNORECASE)
|
|
|
135
151
|
|
|
136
152
|
|
|
137
153
|
|
|
154
|
+
|
|
155
|
+
# Regular expression for Cleaning the tweet msg for proper message
|
|
156
|
+
|
|
138
157
|
tweet = "Insert Random stuff here"
|
|
139
158
|
|
|
140
159
|
|
|
@@ -156,6 +175,9 @@ print(clean_tweet(tweet))
|
|
|
156
175
|
def pln_3():
|
|
157
176
|
print(Fore.RED + '''
|
|
158
177
|
|
|
178
|
+
# pip install nltk spacy
|
|
179
|
+
|
|
180
|
+
|
|
159
181
|
# Apply Stemming on the following words running", "runner", "runs", "easily", "happier", "better”
|
|
160
182
|
|
|
161
183
|
from nltk.stem import PorterStemmer
|
|
@@ -363,7 +385,7 @@ def pln_5():
|
|
|
363
385
|
|
|
364
386
|
# TextBlob
|
|
365
387
|
|
|
366
|
-
pip install -U textblob
|
|
388
|
+
# pip install -U textblob, -r textblob., nltk, -r textblob.download_corpora
|
|
367
389
|
|
|
368
390
|
# pip install -r textblob.download_corpora
|
|
369
391
|
|
|
@@ -596,6 +618,8 @@ def pln_6():
|
|
|
596
618
|
print(Fore.RED + '''
|
|
597
619
|
|
|
598
620
|
|
|
621
|
+
# pip install nltk, spacy
|
|
622
|
+
|
|
599
623
|
import nltk
|
|
600
624
|
from nltk.corpus import brown
|
|
601
625
|
|
|
@@ -771,6 +795,8 @@ print(list(zip(sentence, tags_result)))
|
|
|
771
795
|
def pln_8():
|
|
772
796
|
print(Fore.RED + '''
|
|
773
797
|
|
|
798
|
+
# pip install nltk, spacy, beautifulsoup4, html5lib, requests, lxml, -m spacy download en_core_web_sm
|
|
799
|
+
|
|
774
800
|
import nltk
|
|
775
801
|
from nltk.tokenize import word_tokenize
|
|
776
802
|
from nltk.tag import pos_tag
|
|
@@ -1001,13 +1027,72 @@ while True:
|
|
|
1001
1027
|
print("Chatbot:", chatbot_response(user_input))
|
|
1002
1028
|
break
|
|
1003
1029
|
print("Chatbot:", chatbot_response(user_input))
|
|
1004
|
-
|
|
1030
|
+
|
|
1031
|
+
|
|
1032
|
+
|
|
1033
|
+
|
|
1034
|
+
|
|
1035
|
+
# Chatbot with a simple dialog system
|
|
1036
|
+
|
|
1037
|
+
import random
|
|
1038
|
+
import re
|
|
1039
|
+
|
|
1040
|
+
greetings = ["hi", "hello", "hey", "hola"]
|
|
1041
|
+
responses = {
|
|
1042
|
+
"how are you": "I am doing well, thank you!",
|
|
1043
|
+
"what is your name": "I am a simple chatbot!",
|
|
1044
|
+
"bye": "Goodbye! Have a great day!",
|
|
1045
|
+
"default": "I'm not sure how to respond to that. Can you ask something else?",
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
|
|
1049
|
+
def greet(user_input):
|
|
1050
|
+
if any(greeting in user_input.lower() for greeting in greetings):
|
|
1051
|
+
return random.choice(["Hello!", "Hi there!", "Hey!"])
|
|
1052
|
+
return None
|
|
1053
|
+
|
|
1054
|
+
def get_response(user_input):
|
|
1055
|
+
user_input = user_input.lower()
|
|
1056
|
+
|
|
1057
|
+
greeting_response = greet(user_input)
|
|
1058
|
+
|
|
1059
|
+
if greeting_response:
|
|
1060
|
+
return greeting_response
|
|
1061
|
+
|
|
1062
|
+
for key, value in responses.items():
|
|
1063
|
+
if key in user_input:
|
|
1064
|
+
return value
|
|
1065
|
+
|
|
1066
|
+
return responses["default"]
|
|
1067
|
+
|
|
1068
|
+
def chatbot():
|
|
1069
|
+
print("Chatbot: Hi! How can I help you today? Type 'bye' to exit.")
|
|
1070
|
+
while True:
|
|
1071
|
+
user_input = input("You: ")
|
|
1072
|
+
|
|
1073
|
+
if user_input.lower() == "bye":
|
|
1074
|
+
print("Chatbot: Goodbye! Have a great day!")
|
|
1075
|
+
break
|
|
1076
|
+
|
|
1077
|
+
response = get_response(user_input)
|
|
1078
|
+
|
|
1079
|
+
print("Chatbot:", response)
|
|
1080
|
+
|
|
1081
|
+
if __name__ == "__main__":
|
|
1082
|
+
chatbot()
|
|
1083
|
+
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
|
|
1005
1087
|
|
|
1006
1088
|
''')
|
|
1007
1089
|
|
|
1008
1090
|
def pln_10():
|
|
1009
1091
|
print(Fore.RED + '''
|
|
1010
1092
|
|
|
1093
|
+
# pip install nltk, SpeechRecognition, pydub, google.colab
|
|
1094
|
+
|
|
1095
|
+
|
|
1011
1096
|
import nltk
|
|
1012
1097
|
|
|
1013
1098
|
nltk.download('punkt')
|
|
@@ -1096,4 +1181,102 @@ print("Filtered Words:", words)
|
|
|
1096
1181
|
print("Stemmed:", stemmed)
|
|
1097
1182
|
print("POS Tags:", pos)
|
|
1098
1183
|
|
|
1184
|
+
|
|
1185
|
+
|
|
1186
|
+
|
|
1187
|
+
|
|
1188
|
+
|
|
1189
|
+
# Alternate (Collab)
|
|
1190
|
+
|
|
1191
|
+
!pip install SpeechRecognition pydub
|
|
1192
|
+
import nltk
|
|
1193
|
+
import os
|
|
1194
|
+
from pydub import AudioSegment
|
|
1195
|
+
from google.colab import files
|
|
1196
|
+
|
|
1197
|
+
nltk.download('punkt')
|
|
1198
|
+
nltk.download('stopwords')
|
|
1199
|
+
nltk.download('averaged_perceptron_tagger')
|
|
1200
|
+
nltk.download('wordnet')
|
|
1201
|
+
nltk.download('punkt_tab')
|
|
1202
|
+
nltk.download('averaged_perceptron_tagger_eng')
|
|
1203
|
+
|
|
1204
|
+
print("Please upload 'song.wav' and 'sample.wav' below:")
|
|
1205
|
+
uploaded = files.upload()
|
|
1206
|
+
|
|
1207
|
+
# Identify the actual filenames from the upload
|
|
1208
|
+
song_file = next((f for f in uploaded.keys() if 'song' in f.lower()), "song.wav")
|
|
1209
|
+
sample_file = next((f for f in uploaded.keys() if 'sample' in f.lower()), "sample.wav")
|
|
1210
|
+
|
|
1211
|
+
# Helper function to ensure WAV is in a compatible format (PCM 16-bit)
|
|
1212
|
+
def fix_audio_format(filename):
|
|
1213
|
+
if os.path.exists(filename):
|
|
1214
|
+
try:
|
|
1215
|
+
audio = AudioSegment.from_file(filename)
|
|
1216
|
+
audio.export(filename, format="wav")
|
|
1217
|
+
return True
|
|
1218
|
+
except Exception as e:
|
|
1219
|
+
print(f"Format fix error for {filename}: {e}")
|
|
1220
|
+
return False
|
|
1221
|
+
|
|
1222
|
+
import speech_recognition as sr
|
|
1223
|
+
from nltk.tokenize import word_tokenize
|
|
1224
|
+
from nltk.corpus import stopwords
|
|
1225
|
+
from nltk.stem import PorterStemmer
|
|
1226
|
+
from nltk.stem import WordNetLemmatizer
|
|
1227
|
+
|
|
1228
|
+
# --- Step 1: Speech to Text ---
|
|
1229
|
+
text = "I am learning natural language processing with machine learning"
|
|
1230
|
+
if os.path.exists(song_file):
|
|
1231
|
+
fix_audio_format(song_file)
|
|
1232
|
+
r = sr.Recognizer()
|
|
1233
|
+
try:
|
|
1234
|
+
with sr.AudioFile(song_file) as source:
|
|
1235
|
+
audio = r.record(source, duration=50)
|
|
1236
|
+
text = r.recognize_google(audio)
|
|
1237
|
+
print("\nRecognized Text from", song_file, ":", text)
|
|
1238
|
+
except sr.UnknownValueError:
|
|
1239
|
+
print(f"\nSpeech Recognition could not understand {song_file}. Using default text.")
|
|
1240
|
+
except Exception as e:
|
|
1241
|
+
print(f"\nError processing {song_file}: {e}")
|
|
1242
|
+
|
|
1243
|
+
|
|
1244
|
+
|
|
1245
|
+
# --- Step 2: NLP Processing ---
|
|
1246
|
+
tokens = word_tokenize(text.lower())
|
|
1247
|
+
stop_words = set(stopwords.words("english"))
|
|
1248
|
+
filtered_words = [w for w in tokens if w.isalpha() and w not in stop_words]
|
|
1249
|
+
ps = PorterStemmer()
|
|
1250
|
+
stemmed_words = [ps.stem(w) for w in filtered_words]
|
|
1251
|
+
lemmatizer = WordNetLemmatizer()
|
|
1252
|
+
lemmatized_words = [lemmatizer.lemmatize(w) for w in filtered_words]
|
|
1253
|
+
pos_tags = nltk.pos_tag(filtered_words)
|
|
1254
|
+
|
|
1255
|
+
print("Tokens:", tokens)
|
|
1256
|
+
print("Stemmed Words:", stemmed_words)
|
|
1257
|
+
print("POS Tags:", pos_tags)
|
|
1258
|
+
|
|
1259
|
+
# --- Step 3: Pipeline Function ---
|
|
1260
|
+
def asr_nlp_pipeline(audio_file):
|
|
1261
|
+
if not os.path.exists(audio_file):
|
|
1262
|
+
return f"Error: {audio_file} not found.", [], [], []
|
|
1263
|
+
|
|
1264
|
+
fix_audio_format(audio_file)
|
|
1265
|
+
r = sr.Recognizer()
|
|
1266
|
+
try:
|
|
1267
|
+
with sr.AudioFile(audio_file) as source:
|
|
1268
|
+
audio = r.record(source)
|
|
1269
|
+
text_out = r.recognize_google(audio)
|
|
1270
|
+
tokens_out = word_tokenize(text_out.lower())
|
|
1271
|
+
words_out = [w for w in tokens_out if w.isalpha() and w not in set(stopwords.words('english'))]
|
|
1272
|
+
return text_out, words_out, [PorterStemmer().stem(w) for w in words_out], nltk.pos_tag(words_out)
|
|
1273
|
+
except Exception as e:
|
|
1274
|
+
return f"Error processing {audio_file}: {e}", [], [], []
|
|
1275
|
+
|
|
1276
|
+
if os.path.exists(sample_file):
|
|
1277
|
+
text_res, _, _, _ = asr_nlp_pipeline(sample_file)
|
|
1278
|
+
print("\nPipeline Result for", sample_file, ":", text_res)
|
|
1279
|
+
|
|
1280
|
+
|
|
1281
|
+
|
|
1099
1282
|
''')
|
|
@@ -78,6 +78,7 @@ links <- read.csv("Edges.csv", header=TRUE, as.is=TRUE)
|
|
|
78
78
|
head(links)
|
|
79
79
|
|
|
80
80
|
|
|
81
|
+
|
|
81
82
|
#Basic Network Matrics transformation
|
|
82
83
|
|
|
83
84
|
net <- graph.data.frame(d=links, vertices=nodes, directed=TRUE)
|
|
@@ -259,22 +260,15 @@ centr_betw(g, directed = T, normalized = T)
|
|
|
259
260
|
#Eigenvector centrality
|
|
260
261
|
centr_eigen(g, directed = T, normalized = T)
|
|
261
262
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
263
|
|
|
272
264
|
''')
|
|
273
265
|
|
|
274
266
|
def ans_6():
|
|
275
267
|
print(Fore.RED + '''
|
|
276
268
|
|
|
277
|
-
|
|
269
|
+
# pip install networkx, matplotlib, scipy
|
|
270
|
+
|
|
271
|
+
|
|
278
272
|
import networkx as nx
|
|
279
273
|
import matplotlib.pyplot as plt
|
|
280
274
|
import numpy as np
|
|
@@ -300,6 +294,44 @@ plt.show()
|
|
|
300
294
|
|
|
301
295
|
|
|
302
296
|
|
|
297
|
+
|
|
298
|
+
# Alternate Code for PageRank Visualization
|
|
299
|
+
|
|
300
|
+
import networkx as nx
|
|
301
|
+
import matplotlib.pyplot as plt
|
|
302
|
+
import numpy as np
|
|
303
|
+
|
|
304
|
+
# Define adjacency matrix and node names
|
|
305
|
+
adj = np.array([[0, 1, 1, 0], [0, 0, 1, 0], [1, 0, 0, 1], [0, 0, 1, 0]])
|
|
306
|
+
nodes = ["A", "B", "C", "D"]
|
|
307
|
+
|
|
308
|
+
# Create Directed Graph
|
|
309
|
+
G = nx.from_numpy_array(adj, create_using=nx.DiGraph)
|
|
310
|
+
G = nx.relabel_nodes(G, {i: nodes[i] for i in range(len(nodes))})
|
|
311
|
+
|
|
312
|
+
pr = nx.pagerank(G)
|
|
313
|
+
|
|
314
|
+
print("PageRank Scores:", {n: f"{pr[n]:.4f}" for n in nodes})
|
|
315
|
+
|
|
316
|
+
pos = {"A": (0, 1), "B": (2, 2), "C": (4, 1), "D": (2, 0)}
|
|
317
|
+
|
|
318
|
+
labels = {n: f"{n}\n{pr[n]:.3f}" for n in nodes}
|
|
319
|
+
node_sizes = [800 + 5000 * pr[n] for n in nodes]
|
|
320
|
+
|
|
321
|
+
plt.figure(figsize=(8, 6))
|
|
322
|
+
nx.draw(G, pos, labels=labels,
|
|
323
|
+
node_size=node_sizes,
|
|
324
|
+
node_color="lightblue",
|
|
325
|
+
edgecolors="darkblue",
|
|
326
|
+
font_size=10,
|
|
327
|
+
arrows=True,
|
|
328
|
+
arrowsize=20,
|
|
329
|
+
connectionstyle='arc3, rad = 0.1')
|
|
330
|
+
|
|
331
|
+
plt.title("PageRank Visualization")
|
|
332
|
+
plt.margins(0.2)
|
|
333
|
+
plt.show()
|
|
334
|
+
|
|
303
335
|
|
|
304
336
|
''')
|
|
305
337
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|